Skip to content

Fix 'new' parsing & allow omitting parenthesis #966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 23, 2019
Merged

Fix 'new' parsing & allow omitting parenthesis #966

merged 5 commits into from
Nov 23, 2019

Conversation

dcodeIO
Copy link
Member

@dcodeIO dcodeIO commented Nov 19, 2019

This fixes #932 by adding more specific code to parse new expressions, also handling new SomeClass without parenthesis.

As it stands, the parsing is not quite JS-like in that it expects an identifier or series of identifiers (combined to a property access) as the target, assuming that anything else (like new (getSomeCtor())) can't be constructed anyway in AS.

@dcodeIO
Copy link
Member Author

dcodeIO commented Nov 20, 2019

Last commit makes it so that new takes a TypeName, not an expression anymore, potentially opening up that function test<T>(): T { return new T(); } feature we discussed in the past. It doesn't do this yet, however, just figured that if this isn't JS-like anyway, we may as well go as far.

Also cleans up quite a bit of parser code. Along with the tokenizer, the parser belongs to the oldest code we have, and it should be possible to clean it up even more with today's knowledge - but leaving that to follow-up PRs.

@MaxGraey
Copy link
Member

MaxGraey commented Nov 20, 2019

It will be also great hint about constructor (it couldn't be a public or has different signature):

function test1<T extends { new(): T }>(): T {
  return new T();
}

function test1<T extends { new(a: i32): T }>(): T {
  return new T(123);
}

@dcodeIO dcodeIO merged commit 92a768f into master Nov 23, 2019
@dcodeIO dcodeIO deleted the issue-932 branch January 1, 2020 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't resolve method call with constructor without parenthesis
2 participants