8000 parse module specifier as string (old logic is kept for better error … · imskojs/TypeScript@e88dfb1 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit e88dfb1

Browse files
committed
parse module specifier as string (old logic is kept for better error recovery)
1 parent 3a4ac33 commit e88dfb1

File tree

5 files changed

+59
-8
lines changed

5 files changed

+59
-8
lines changed

src/compiler/parser.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5310,16 +5310,17 @@ namespace ts {
53105310
}
53115311

53125312
function parseModuleSpecifier(): Expression {
5313-
// We allow arbitrary expressions here, even though the grammar only allows string
5314-
// literals. We check to ensure that it is only a string literal later in the grammar
5315-
// walker.
5316-
const result = parseExpression();
5317-
// Ensure the string being required is in our 'identifier' table. This will ensure
5318-
// that features like 'find refs' will look inside this file when search for its name.
5319-
if (result.kind === SyntaxKind.StringLiteral) {
5313+
if (token === SyntaxKind.StringLiteral) {
5314+
const result = parseLiteralNode();
53205315
internIdentifier((<LiteralExpression>result).text);
5316+
return result;
5317+
}
5318+
else {
5319+
// We allow arbitrary expressions here, even though the grammar only allows string
5320+
// literals. We check to ensure that it is only a string literal later in the grammar
5321+
// check pass.
5322+
return parseExpression();
53215323
}
5322-
return result;
53235324
}
53245325

53255326
function parseNamespaceImport(): NamespaceImport {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [tests/cases/compiler/missingSemicolonInModuleSpecifier.ts] ////
2+
3+
//// [a.ts]
4+
5+
export const x = 1;
6+
7+
//// [b.ts]
8+
import {x} from "./a"
9+
(function() { return 1; }())
10+
11+
//// [a.js]
12+
"use strict";
13+
exports.x = 1;
14+
//// [b.js]
15+
"use strict";
16+
(function () { return 1; }());
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/compiler/a.ts ===
2+
3+
export const x = 1;
4+
>x : Symbol(x, Decl(a.ts, 1, 12))
5+
6+
=== tests/cases/compiler/b.ts ===
7+
import {x} from "./a"
8+
>x : Symbol(x, Decl(b.ts, 0, 8))
9+
10+
(function() { return 1; }())
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== tests/cases/compiler/a.ts ===
2+
3+
export const x = 1;
4+
>x : number
5+
>1 : number
6+
7+
=== tests/cases/compiler/b.ts ===
8+
import {x} from "./a"
9+
>x : number
10+
11+
(function() { return 1; }())
12+
>(function() { return 1; }()) : number
13+
>function() { return 1; }() : number
14+
>function() { return 1; } : () => number
15+
>1 : number
16+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @module: commonjs
2+
3+
// @filename: a.ts
4+
export const x = 1;
5+
6+
// @filename: b.ts
7+
import {x} from "./a"
8+
(function() { return 1; }())

0 commit comments

Comments
 (0)
0