-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5bd8271
commit 4f1b908
Showing
9 changed files
with
100 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
sheetalkamat
Author
Member
|
||
} | ||
|
||
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); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
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"); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 12 additions & 0 deletions
12
tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |
8 changes: 8 additions & 0 deletions
8
tests/baselines/reference/es6ImportWithoutFromClauseInEs5.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// @target: es6 | ||
// @module: commonjs | ||
|
||
import 10; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// @target: es6 | ||
// @module: commonjs | ||
|
||
// @filename: es6ImportWithoutFromClause_0.ts | ||
export var a = 10; | ||
|
||
// @filename: es6ImportWithoutFromClause_1.ts | ||
import "es6ImportWithoutFromClause_0"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// @target: es5 | ||
// @module: commonjs | ||
|
||
// @filename: es6ImportWithoutFromClauseInEs5_0.ts | ||
export var a = 10; | ||
|
||
// @filename: es6ImportWithoutFromClauseInEs5_1.ts | ||
import "es6ImportWithoutFromClauseInEs5_0"; |
How does this type check? You are returning an ImportStatement, when the stated return type is ImportEqualsDeclaration? Seems incorrect