Parsing for import * as ImportedBinding
This commit is contained in:
parent
4f1b908212
commit
fdd7032c61
|
@ -4520,7 +4520,8 @@ module ts {
|
|||
|
||||
function parseImportDeclarationOrStatement(fullStart: number, modifiers: ModifiersArray): ImportEqualsDeclaration | ImportStatement {
|
||||
parseExpected(SyntaxKind.ImportKeyword);
|
||||
if (token === SyntaxKind.StringLiteral) {
|
||||
if (token === SyntaxKind.StringLiteral ||
|
||||
token === SyntaxKind.AsteriskToken) {
|
||||
return parseImportStatement(fullStart, modifiers);
|
||||
}
|
||||
|
||||
|
@ -4564,7 +4565,12 @@ module ts {
|
|||
setModifiers(node, modifiers);
|
||||
|
||||
// ImportDeclaration:
|
||||
// import ImportClause ModuleSpecifier ;
|
||||
// import ModuleSpecifier;
|
||||
if (token !== SyntaxKind.StringLiteral) {
|
||||
// ImportDeclaration:
|
||||
node.importClause = parseImportClause();
|
||||
}
|
||||
node.moduleSpecifier = parseModuleSpecifier();
|
||||
parseSemicolon();
|
||||
return finishNode(node);
|
||||
|
@ -4583,6 +4589,30 @@ module ts {
|
|||
parseErrorAtCurrentToken(Diagnostics.String_literal_expected);
|
||||
}
|
||||
|
||||
function parseImportClause(): ImportClause {
|
||||
//ImportClause:
|
||||
// ImportedDefaultBinding from
|
||||
// NameSpaceImport from
|
||||
// NamedImports from
|
||||
// ImportedDefaultBinding, NameSpaceImport from
|
||||
// ImportedDefaultBinding, NamedImports from
|
||||
|
||||
var importClause = <ImportClause>createNode(SyntaxKind.ImportClause);
|
||||
importClause.bindings = parseNamespaceImport();
|
||||
parseExpected(SyntaxKind.FromKeyword);
|
||||
return finishNode(importClause);
|
||||
}
|
||||
|
||||
function parseNamespaceImport(): NamespaceImport {
|
||||
// NameSpaceImport:
|
||||
// * as ImportedBinding
|
||||
var namespaceImport = <NamespaceImport>createNode(SyntaxKind.NamespaceImport);
|
||||
parseExpected(SyntaxKind.AsteriskToken);
|
||||
parseExpected(SyntaxKind.AsKeyword);
|
||||
namespaceImport.name = parseIdentifier();
|
||||
return finishNode(namespaceImport);
|
||||
}
|
||||
|
||||
function parseExportAssignmentTail(fullStart: number, modifiers: ModifiersArray): ExportAssignment {
|
||||
var node = <ExportAssignment>createNode(SyntaxKind.ExportAssignment, fullStart);
|
||||
setModifiers(node, modifiers);
|
||||
|
@ -4612,6 +4642,8 @@ module ts {
|
|||
// Not true keywords so ensure an identifier follows
|
||||
return lookAhead(nextTokenIsIdentifierOrKeyword);
|
||||
case SyntaxKind.ImportKeyword:
|
||||
// Not true keywords so ensure an identifier follows or is string literal or asterisk
|
||||
return lookAhead(nextTokenIsIdentifierOrKeywordOrStringLiteralOrAsterisk) ;
|
||||
case SyntaxKind.ModuleKeyword:
|
||||
// Not a true keyword so ensure an identifier or string literal follows
|
||||
return lookAhead(nextTokenIsIdentifierOrKeywordOrStringLiteral);
|
||||
|
@ -4642,6 +4674,12 @@ module ts {
|
|||
return isIdentifierOrKeyword() || token === SyntaxKind.StringLiteral;
|
||||
}
|
||||
|
||||
function nextTokenIsIdentifierOrKeywordOrStringLiteralOrAsterisk() {
|
||||
nextToken();
|
||||
return isIdentifierOrKeyword() || token === SyntaxKind.StringLiteral ||
|
||||
token === SyntaxKind.AsteriskToken;
|
||||
}
|
||||
|
||||
function nextTokenIsEqualsTokenOrDeclarationStart() {
|
||||
nextToken();
|
||||
return token === SyntaxKind.EqualsToken || isDeclarationStart();
|
||||
|
|
|
@ -38,6 +38,7 @@ module ts {
|
|||
|
||||
var textToToken: Map<SyntaxKind> = {
|
||||
"any": SyntaxKind.AnyKeyword,
|
||||
"as": SyntaxKind.AsKeyword,
|
||||
"boolean": SyntaxKind.BooleanKeyword,
|
||||
"break": SyntaxKind.BreakKeyword,
|
||||
"case": SyntaxKind.CaseKeyword,
|
||||
|
@ -58,6 +59,7 @@ module ts {
|
|||
"false": SyntaxKind.FalseKeyword,
|
||||
"finally": SyntaxKind.FinallyKeyword,
|
||||
"for": SyntaxKind.ForKeyword,
|
||||
"from": SyntaxKind.FromKeyword,
|
||||
"function": SyntaxKind.FunctionKeyword,
|
||||
"get": SyntaxKind.GetKeyword,
|
||||
"if": SyntaxKind.IfKeyword,
|
||||
|
|
|
@ -120,6 +120,8 @@ module ts {
|
|||
WhileKeyword,
|
||||
WithKeyword,
|
||||
// Strict mode reserved words
|
||||
AsKeyword,
|
||||
FromKeyword,
|
||||
ImplementsKeyword,
|
||||
InterfaceKeyword,
|
||||
LetKeyword,
|
||||
|
|
12
tests/baselines/reference/es6ImportNameSpaceImport.js
Normal file
12
tests/baselines/reference/es6ImportNameSpaceImport.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
//// [tests/cases/compiler/es6ImportNameSpaceImport.ts] ////
|
||||
|
||||
//// [es6ImportNameSpaceImport_0.ts]
|
||||
|
||||
export var a = 10;
|
||||
|
||||
//// [es6ImportNameSpaceImport_1.ts]
|
||||
import * as nameSpaceBinding from "es6ImportNameSpaceImport_0";
|
||||
|
||||
//// [es6ImportNameSpaceImport_0.js]
|
||||
exports.a = 10;
|
||||
//// [es6ImportNameSpaceImport_1.js]
|
8
tests/baselines/reference/es6ImportNameSpaceImport.types
Normal file
8
tests/baselines/reference/es6ImportNameSpaceImport.types
Normal file
|
@ -0,0 +1,8 @@
|
|||
=== tests/cases/compiler/es6ImportNameSpaceImport_0.ts ===
|
||||
|
||||
export var a = 10;
|
||||
>a : number
|
||||
|
||||
=== tests/cases/compiler/es6ImportNameSpaceImport_1.ts ===
|
||||
import * as nameSpaceBinding from "es6ImportNameSpaceImport_0";
|
||||
No type information for this code.
|
12
tests/baselines/reference/es6ImportNameSpaceImportInEs5.js
Normal file
12
tests/baselines/reference/es6ImportNameSpaceImportInEs5.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
//// [tests/cases/compiler/es6ImportNameSpaceImportInEs5.ts] ////
|
||||
|
||||
//// [es6ImportNameSpaceImportInEs5_0.ts]
|
||||
|
||||
export var a = 10;
|
||||
|
||||
//// [es6ImportNameSpaceImportInEs5_1.ts]
|
||||
import * as nameSpaceBinding from "es6ImportNameSpaceImportInEs5_0";
|
||||
|
||||
//// [es6ImportNameSpaceImportInEs5_0.js]
|
||||
exports.a = 10;
|
||||
//// [es6ImportNameSpaceImportInEs5_1.js]
|
|
@ -0,0 +1,8 @@
|
|||
=== tests/cases/compiler/es6ImportNameSpaceImportInEs5_0.ts ===
|
||||
|
||||
export var a = 10;
|
||||
>a : number
|
||||
|
||||
=== tests/cases/compiler/es6ImportNameSpaceImportInEs5_1.ts ===
|
||||
import * as nameSpaceBinding from "es6ImportNameSpaceImportInEs5_0";
|
||||
No type information for this code.
|
8
tests/cases/compiler/es6ImportNameSpaceImport.ts
Normal file
8
tests/cases/compiler/es6ImportNameSpaceImport.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
// @target: es6
|
||||
// @module: commonjs
|
||||
|
||||
// @filename: es6ImportNameSpaceImport_0.ts
|
||||
export var a = 10;
|
||||
|
||||
// @filename: es6ImportNameSpaceImport_1.ts
|
||||
import * as nameSpaceBinding from "es6ImportNameSpaceImport_0";
|
8
tests/cases/compiler/es6ImportNameSpaceImportInEs5.ts
Normal file
8
tests/cases/compiler/es6ImportNameSpaceImportInEs5.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
// @target: es5
|
||||
// @module: commonjs
|
||||
|
||||
// @filename: es6ImportNameSpaceImportInEs5_0.ts
|
||||
export var a = 10;
|
||||
|
||||
// @filename: es6ImportNameSpaceImportInEs5_1.ts
|
||||
import * as nameSpaceBinding from "es6ImportNameSpaceImportInEs5_0";
|
Loading…
Reference in a new issue