mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Some refactoring of how import specifiers are parsed as per code review feedback
This commit is contained in:
+13
-3
@@ -4656,11 +4656,21 @@ module ts {
|
||||
// ImportSpecifier:
|
||||
// ImportedBinding
|
||||
// IdentifierName as ImportedBinding
|
||||
if (lookAhead(nextTokenIsAsKeyword)) {
|
||||
node.propertyName = parseIdentifierName();
|
||||
var isfirstIdentifierNameNotAnIdentifier = isKeyword(token) && !isIdentifier();
|
||||
var start = scanner.getTokenPos();
|
||||
var identifierName = parseIdentifierName();
|
||||
if (token === SyntaxKind.AsKeyword) {
|
||||
node.propertyName = identifierName;
|
||||
parseExpected(SyntaxKind.AsKeyword);
|
||||
node.name = parseIdentifier();
|
||||
}
|
||||
else {
|
||||
node.name = identifierName;
|
||||
if (isfirstIdentifierNameNotAnIdentifier) {
|
||||
// Report error identifier expected
|
||||
parseErrorAtPosition(start, identifierName.end - start, Diagnostics.Identifier_expected);
|
||||
}
|
||||
}
|
||||
node.name = parseIdentifier();
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(3,10): error TS1003: Identifier expected.
|
||||
tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(4,19): error TS1003: Identifier expected.
|
||||
tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(6,21): error TS1003: Identifier expected.
|
||||
|
||||
|
||||
==== tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts (3 errors) ====
|
||||
|
||||
import { yield } from "somemodule"; // Allowed
|
||||
import { default } from "somemodule"; // Error - as this is keyword that is not allowed as identifier
|
||||
~~~~~~~
|
||||
!!! error TS1003: Identifier expected.
|
||||
import { yield as default } from "somemodule"; // error to use default as binding name
|
||||
~~~~~~~
|
||||
!!! error TS1003: Identifier expected.
|
||||
import { default as yield } from "somemodule"; // no error
|
||||
import { default as default } from "somemodule"; // default as is ok, error of default binding name
|
||||
~~~~~~~
|
||||
!!! error TS1003: Identifier expected.
|
||||
@@ -0,0 +1,8 @@
|
||||
// @target: es6
|
||||
// @module: commonjs
|
||||
|
||||
import { yield } from "somemodule"; // Allowed
|
||||
import { default } from "somemodule"; // Error - as this is keyword that is not allowed as identifier
|
||||
import { yield as default } from "somemodule"; // error to use default as binding name
|
||||
import { default as yield } from "somemodule"; // no error
|
||||
import { default as default } from "somemodule"; // default as is ok, error of default binding name
|
||||
Reference in New Issue
Block a user