// @target es6
// @filename: file1.ts
let stuff1 = new Array<string>;
// @filename: file2.ts
let stuff2 = new Map<string, number>;
This code currently errors with
'(' expected.
I actually don't care if this code should be allowed or not.
Maybe it should, in which case this is a bug on needing to allow the code.
Maybe it shouldn't, in which case I think we should give a better error message like
A 'new' expression with type arguments must always be followed by a parenthesized argument list.
Approximately infinity years ago we decided that parens were required in this case, to simplify the grammar and reduce the chances of ambiguity.
@DanielRosenwasser I want to working on it, can I take this? Could you please add more info about how to fix it?
src/compiler/diagnosticMessages.jsonnpx gulp generate-diagnosticsIn src/compiler/parser.ts
you'll want to write something like
if (token() === SyntaxKind.OpenParenToken) {
node.arguments = parseArgumentList();
}
else if (node.typeArguments) {
// issue the error here using parseErrorAt(fullStart, scanner.getStartPos(), ...)
}
Try running npx gulp runtests-parallel. There is at least one test that should break:
Run npx gulp baseline-accept
Thanks @Rustin-Liu!
Most helpful comment
Approximately infinity years ago we decided that parens were required in this case, to simplify the grammar and reduce the chances of ambiguity.