Parsing for default binding import syntax

This commit is contained in:
Sheetal Nandi 2015-01-27 16:43:46 -08:00
parent 5eb009461e
commit 69fef6e544
20 changed files with 252 additions and 10 deletions

View File

@ -4523,11 +4523,18 @@ module ts {
return nextToken() === SyntaxKind.OpenParenToken;
}
function nextTokenIsCommaOrFromKeyword() {
nextToken();
return token === SyntaxKind.CommaToken ||
token === SyntaxKind.FromKeyword;
}
function parseImportDeclarationOrStatement(fullStart: number, modifiers: ModifiersArray): ImportEqualsDeclaration | ImportStatement {
parseExpected(SyntaxKind.ImportKeyword);
if (token === SyntaxKind.StringLiteral ||
token === SyntaxKind.AsteriskToken ||
token === SyntaxKind.OpenBraceToken) {
token === SyntaxKind.OpenBraceToken ||
(isIdentifier() && lookAhead(nextTokenIsCommaOrFromKeyword))) {
return parseImportStatement(fullStart, modifiers);
}
@ -4604,7 +4611,19 @@ module ts {
// ImportedDefaultBinding, NamedImports from
var importClause = <ImportClause>createNode(SyntaxKind.ImportClause);
importClause.bindings = token === SyntaxKind.AsteriskToken ? parseNamespaceImport() : parseNamedImports();
if (isIdentifier()) {
// ImportedDefaultBinding:
// ImportedBinding
importClause.defaultBinding = parseIdentifier();
}
// If there was no default import or if there is comma token after default import
// parse namespace or named imports
if (!importClause.defaultBinding ||
parseOptional(SyntaxKind.CommaToken)) {
importClause.bindings = token === SyntaxKind.AsteriskToken ? parseNamespaceImport() : parseNamedImports();
}
parseExpected(SyntaxKind.FromKeyword);
return finishNode(importClause);
}

View File

@ -0,0 +1,12 @@
//// [tests/cases/compiler/es6ImportDefaultBinding.ts] ////
//// [es6ImportDefaultBinding_0.ts]
export var a = 10;
//// [es6ImportDefaultBinding_1.ts]
import defaultBinding from "es6ImportDefaultBinding_0";
//// [es6ImportDefaultBinding_0.js]
exports.a = 10;
//// [es6ImportDefaultBinding_1.js]

View File

@ -0,0 +1,8 @@
=== tests/cases/compiler/es6ImportDefaultBinding_0.ts ===
export var a = 10;
>a : number
=== tests/cases/compiler/es6ImportDefaultBinding_1.ts ===
import defaultBinding from "es6ImportDefaultBinding_0";
No type information for this code.

View File

@ -0,0 +1,21 @@
//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts] ////
//// [es6ImportDefaultBindingFollowedWithNamedImport_0.ts]
export var a = 10;
export var x = a;
export var m = a;
//// [es6ImportDefaultBindingFollowedWithNamedImport_1.ts]
import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0";
import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0";
import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0";
import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0";
import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0";
import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0";
//// [es6ImportDefaultBindingFollowedWithNamedImport_0.js]
exports.a = 10;
exports.x = exports.a;
exports.m = exports.a;
//// [es6ImportDefaultBindingFollowedWithNamedImport_1.js]

View File

@ -0,0 +1,21 @@
=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0.ts ===
export var a = 10;
>a : number
export var x = a;
>x : number
>a : number
export var m = a;
>m : number
>a : number
=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts ===
import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0";
No type information for this code.import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0";
No type information for this code.import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0";
No type information for this code.import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0";
No type information for this code.import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0";
No type information for this code.import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0";
No type information for this code.

View File

@ -0,0 +1,21 @@
//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5.ts] ////
//// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_0.ts]
export var a = 10;
export var x = a;
export var m = a;
//// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts]
import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0";
import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0";
import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0";
import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0";
import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0";
import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0";
//// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_0.js]
exports.a = 10;
exports.x = exports.a;
exports.m = exports.a;
//// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.js]

View File

@ -0,0 +1,21 @@
=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0.ts ===
export var a = 10;
>a : number
export var x = a;
>x : number
>a : number
export var m = a;
>m : number
>a : number
=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts ===
import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0";
No type information for this code.import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0";
No type information for this code.import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0";
No type information for this code.import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0";
No type information for this code.import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0";
No type information for this code.import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0";
No type information for this code.

View File

@ -0,0 +1,12 @@
//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts] ////
//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.ts]
export var a = 10;
//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts]
import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0";
//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.js]
exports.a = 10;
//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.js]

View File

@ -0,0 +1,8 @@
=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_0.ts ===
export var a = 10;
>a : number
=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts ===
import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0";
No type information for this code.

View File

@ -0,0 +1,12 @@
//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.ts] ////
//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.ts]
export var a = 10;
//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts]
import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0";
//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.js]
exports.a = 10;
//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.js]

View File

@ -0,0 +1,8 @@
=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.ts ===
export var a = 10;
>a : number
=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts ===
import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0";
No type information for this code.

View File

@ -0,0 +1,12 @@
//// [tests/cases/compiler/es6ImportDefaultBindingInEs5.ts] ////
//// [es6ImportDefaultBindingInEs5_0.ts]
export var a = 10;
//// [es6ImportDefaultBindingInEs5_1.ts]
import defaultBinding from "es6ImportDefaultBindingInEs5_0";
//// [es6ImportDefaultBindingInEs5_0.js]
exports.a = 10;
//// [es6ImportDefaultBindingInEs5_1.js]

View File

@ -0,0 +1,8 @@
=== tests/cases/compiler/es6ImportDefaultBindingInEs5_0.ts ===
export var a = 10;
>a : number
=== tests/cases/compiler/es6ImportDefaultBindingInEs5_1.ts ===
import defaultBinding from "es6ImportDefaultBindingInEs5_0";
No type information for this code.

View File

@ -2,9 +2,8 @@ tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,10): error TS1003:
tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,12): error TS1109: Expression expected.
tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,14): error TS2304: Cannot find name 'from'.
tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,19): error TS1005: ';' expected.
tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,22): error TS1005: '=' expected.
tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,24): error TS2304: Cannot find name 'from'.
tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,29): error TS1005: ';' expected.
tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,24): error TS1005: '{' expected.
tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,29): error TS1005: ',' expected.
==== tests/cases/compiler/es6ImportNamedImportParsingError_0.ts (0 errors) ====
@ -13,7 +12,7 @@ tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,29): error TS1005:
export var x = a;
export var m = a;
==== tests/cases/compiler/es6ImportNamedImportParsingError_1.ts (7 errors) ====
==== tests/cases/compiler/es6ImportNamedImportParsingError_1.ts (6 errors) ====
import { * } from "es6ImportNamedImportParsingError_0";
~
!!! error TS1003: Identifier expected.
@ -24,9 +23,7 @@ tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,29): error TS1005:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1005: ';' expected.
import defaultBinding, from "es6ImportNamedImportParsingError_0";
~
!!! error TS1005: '=' expected.
~~~~
!!! error TS2304: Cannot find name 'from'.
!!! error TS1005: '{' expected.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1005: ';' expected.
!!! error TS1005: ',' expected.

View File

@ -0,0 +1,8 @@
// @target: es6
// @module: commonjs
// @filename: es6ImportDefaultBinding_0.ts
export var a = 10;
// @filename: es6ImportDefaultBinding_1.ts
import defaultBinding from "es6ImportDefaultBinding_0";

View File

@ -0,0 +1,15 @@
// @target: es6
// @module: commonjs
// @filename: es6ImportDefaultBindingFollowedWithNamedImport_0.ts
export var a = 10;
export var x = a;
export var m = a;
// @filename: es6ImportDefaultBindingFollowedWithNamedImport_1.ts
import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0";
import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0";
import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0";
import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0";
import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0";
import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0";

View File

@ -0,0 +1,15 @@
// @target: es5
// @module: commonjs
// @filename: es6ImportDefaultBindingFollowedWithNamedImportInEs5_0.ts
export var a = 10;
export var x = a;
export var m = a;
// @filename: es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts
import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0";
import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0";
import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0";
import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0";
import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0";
import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0";

View File

@ -0,0 +1,8 @@
// @target: es6
// @module: commonjs
// @filename: es6ImportDefaultBindingFollowedWithNamespaceBinding_0.ts
export var a = 10;
// @filename: es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts
import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0";

View File

@ -0,0 +1,8 @@
// @target: es5
// @module: commonjs
// @filename: es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.ts
export var a = 10;
// @filename: es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts
import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0";

View File

@ -0,0 +1,8 @@
// @target: es5
// @module: commonjs
// @filename: es6ImportDefaultBindingInEs5_0.ts
export var a = 10;
// @filename: es6ImportDefaultBindingInEs5_1.ts
import defaultBinding from "es6ImportDefaultBindingInEs5_0";