Parse import ModuleSpecifier;
This commit is contained in:
parent
5bd8271f04
commit
4f1b908212
|
@ -1511,7 +1511,6 @@ module ts {
|
|||
return token === SyntaxKind.GreaterThanToken || token === SyntaxKind.OpenParenToken;
|
||||
case ParsingContext.HeritageClauses:
|
||||
return token === SyntaxKind.OpenBraceToken || token === SyntaxKind.CloseBraceToken;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4519,10 +4518,14 @@ module ts {
|
|||
return nextToken() === SyntaxKind.OpenParenToken;
|
||||
}
|
||||
|
||||
function parseImportEqualsDeclaration(fullStart: number, modifiers: ModifiersArray): ImportEqualsDeclaration {
|
||||
function parseImportDeclarationOrStatement(fullStart: number, modifiers: ModifiersArray): ImportEqualsDeclaration | ImportStatement {
|
||||
parseExpected(SyntaxKind.ImportKeyword);
|
||||
if (token === SyntaxKind.StringLiteral) {
|
||||
return parseImportStatement(fullStart, modifiers);
|
||||
}
|
||||
|
||||
var node = <ImportEqualsDeclaration>createNode(SyntaxKind.ImportEqualsDeclaration, fullStart);
|
||||
setModifiers(node, modifiers);
|
||||
parseExpected(SyntaxKind.ImportKeyword);
|
||||
node.name = parseIdentifier();
|
||||
parseExpected(SyntaxKind.EqualsToken);
|
||||
node.moduleReference = parseModuleReference();
|
||||
|
@ -4556,6 +4559,30 @@ module ts {
|
|||
return finishNode(node);
|
||||
}
|
||||
|
||||
function parseImportStatement(fullStart: number, modifiers: ModifiersArray): ImportStatement {
|
||||
var node = <ImportStatement>createNode(SyntaxKind.ImportStatement, fullStart);
|
||||
setModifiers(node, modifiers);
|
||||
|
||||
// ImportDeclaration:
|
||||
// import ModuleSpecifier;
|
||||
node.moduleSpecifier = parseModuleSpecifier();
|
||||
parseSemicolon();
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
function parseModuleSpecifier(): StringLiteralExpression {
|
||||
// ModuleSpecifier:
|
||||
// StringLiteral
|
||||
if (token === SyntaxKind.StringLiteral) {
|
||||
// Ensure the string being required is in our 'identifier' table. This will ensure
|
||||
// that features like 'find refs' will look inside this file when search for its name.
|
||||
var moduleSpecifier = <StringLiteralExpression>parseLiteralNode(/*internName*/ true);
|
||||
return moduleSpecifier;
|
||||
}
|
||||
|
||||
parseErrorAtCurrentToken(Diagnostics.String_literal_expected);
|
||||
}
|
||||
|
||||
function parseExportAssignmentTail(fullStart: number, modifiers: ModifiersArray): ExportAssignment {
|
||||
var node = <ExportAssignment>createNode(SyntaxKind.ExportAssignment, fullStart);
|
||||
setModifiers(node, modifiers);
|
||||
|
@ -4581,10 +4608,10 @@ module ts {
|
|||
case SyntaxKind.ClassKeyword:
|
||||
case SyntaxKind.InterfaceKeyword:
|
||||
case SyntaxKind.EnumKeyword:
|
||||
case SyntaxKind.ImportKeyword:
|
||||
case SyntaxKind.TypeKeyword:
|
||||
// Not true keywords so ensure an identifier follows
|
||||
return lookAhead(nextTokenIsIdentifierOrKeyword);
|
||||
case SyntaxKind.ImportKeyword:
|
||||
case SyntaxKind.ModuleKeyword:
|
||||
// Not a true keyword so ensure an identifier or string literal follows
|
||||
return lookAhead(nextTokenIsIdentifierOrKeywordOrStringLiteral);
|
||||
|
@ -4653,7 +4680,7 @@ module ts {
|
|||
case SyntaxKind.ModuleKeyword:
|
||||
return parseModuleDeclaration(fullStart, modifiers);
|
||||
case SyntaxKind.ImportKeyword:
|
||||
return parseImportEqualsDeclaration(fullStart, modifiers);
|
||||
return parseImportDeclarationOrStatement(fullStart, modifiers);
|
||||
default:
|
||||
Debug.fail("Mismatch between isDeclarationStart and parseDeclaration");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
tests/cases/compiler/es6ImportParseErrors.ts(2,1): error TS1128: Declaration or statement expected.
|
||||
|
||||
|
||||
==== tests/cases/compiler/es6ImportParseErrors.ts (1 errors) ====
|
||||
|
||||
import 10;
|
||||
~~~~~~
|
||||
!!! error TS1128: Declaration or statement expected.
|
12
tests/baselines/reference/es6ImportWithoutFromClause.js
Normal file
12
tests/baselines/reference/es6ImportWithoutFromClause.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
//// [tests/cases/compiler/es6ImportWithoutFromClause.ts] ////
|
||||
|
||||
//// [es6ImportWithoutFromClause_0.ts]
|
||||
|
||||
export var a = 10;
|
||||
|
||||
//// [es6ImportWithoutFromClause_1.ts]
|
||||
import "es6ImportWithoutFromClause_0";
|
||||
|
||||
//// [es6ImportWithoutFromClause_0.js]
|
||||
exports.a = 10;
|
||||
//// [es6ImportWithoutFromClause_1.js]
|
|
@ -0,0 +1,8 @@
|
|||
=== tests/cases/compiler/es6ImportWithoutFromClause_0.ts ===
|
||||
|
||||
export var a = 10;
|
||||
>a : number
|
||||
|
||||
=== tests/cases/compiler/es6ImportWithoutFromClause_1.ts ===
|
||||
import "es6ImportWithoutFromClause_0";
|
||||
No type information for this code.
|
12
tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js
Normal file
12
tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
//// [tests/cases/compiler/es6ImportWithoutFromClauseInEs5.ts] ////
|
||||
|
||||
//// [es6ImportWithoutFromClauseInEs5_0.ts]
|
||||
|
||||
export var a = 10;
|
||||
|
||||
//// [es6ImportWithoutFromClauseInEs5_1.ts]
|
||||
import "es6ImportWithoutFromClauseInEs5_0";
|
||||
|
||||
//// [es6ImportWithoutFromClauseInEs5_0.js]
|
||||
exports.a = 10;
|
||||
//// [es6ImportWithoutFromClauseInEs5_1.js]
|
|
@ -0,0 +1,8 @@
|
|||
=== tests/cases/compiler/es6ImportWithoutFromClauseInEs5_0.ts ===
|
||||
|
||||
export var a = 10;
|
||||
>a : number
|
||||
|
||||
=== tests/cases/compiler/es6ImportWithoutFromClauseInEs5_1.ts ===
|
||||
import "es6ImportWithoutFromClauseInEs5_0";
|
||||
No type information for this code.
|
4
tests/cases/compiler/es6ImportParseErrors.ts
Normal file
4
tests/cases/compiler/es6ImportParseErrors.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
// @target: es6
|
||||
// @module: commonjs
|
||||
|
||||
import 10;
|
8
tests/cases/compiler/es6ImportWithoutFromClause.ts
Normal file
8
tests/cases/compiler/es6ImportWithoutFromClause.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
// @target: es6
|
||||
// @module: commonjs
|
||||
|
||||
// @filename: es6ImportWithoutFromClause_0.ts
|
||||
export var a = 10;
|
||||
|
||||
// @filename: es6ImportWithoutFromClause_1.ts
|
||||
import "es6ImportWithoutFromClause_0";
|
8
tests/cases/compiler/es6ImportWithoutFromClauseInEs5.ts
Normal file
8
tests/cases/compiler/es6ImportWithoutFromClauseInEs5.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
// @target: es5
|
||||
// @module: commonjs
|
||||
|
||||
// @filename: es6ImportWithoutFromClauseInEs5_0.ts
|
||||
export var a = 10;
|
||||
|
||||
// @filename: es6ImportWithoutFromClauseInEs5_1.ts
|
||||
import "es6ImportWithoutFromClauseInEs5_0";
|
Loading…
Reference in a new issue