Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 24d8f79

Browse filesBrowse files
authored
Fix crash in emitTokenWithComment (microsoft#36542)
1 parent 80ad0de commit 24d8f79
Copy full SHA for 24d8f79

4 files changed

+39-3Lines changed: 39 additions & 3 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/emitter.ts‎

Copy file name to clipboardExpand all lines: src/compiler/emitter.ts
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,11 +2744,11 @@ namespace ts {
27442744
const node = getParseTreeNode(contextNode);
27452745
const isSimilarNode = node && node.kind === contextNode.kind;
27462746
const startPos = pos;
2747-
if (isSimilarNode) {
2748-
pos = skipTrivia(currentSourceFile!.text, pos);
2747+
if (isSimilarNode && currentSourceFile) {
2748+
pos = skipTrivia(currentSourceFile.text, pos);
27492749
}
27502750
if (emitLeadingCommentsOfPosition && isSimilarNode && contextNode.pos !== startPos) {
2751-
const needsIndent = indentLeading && !positionsAreOnSameLine(startPos, pos, currentSourceFile!);
2751+
const needsIndent = indentLeading && currentSourceFile && !positionsAreOnSameLine(startPos, pos, currentSourceFile);
27522752
if (needsIndent) {
27532753
increaseIndent();
27542754
}
Collapse file
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
tests/cases/compiler/crashInEmitTokenWithComment.ts(5,4): error TS2345: Argument of type '({ [foo.bar]: c }: {}) => any' is not assignable to parameter of type 'string'.
2+
tests/cases/compiler/crashInEmitTokenWithComment.ts(5,7): error TS2537: Type '{}' has no matching index signature for type 'string'.
3+
4+
5+
==== tests/cases/compiler/crashInEmitTokenWithComment.ts (2 errors) ====
6+
// GH#32358
7+
const fn = (param: string) => undefined;
8+
9+
const foo = {bar: 'a'};
10+
fn(({[foo.bar]: c}) => undefined);
11+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12+
!!! error TS2345: Argument of type '({ [foo.bar]: c }: {}) => any' is not assignable to parameter of type 'string'.
13+
~~~~~~~
14+
!!! error TS2537: Type '{}' has no matching index signature for type 'string'.
Collapse file
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//// [crashInEmitTokenWithComment.ts]
2+
// GH#32358
3+
const fn = (param: string) => undefined;
4+
5+
const foo = {bar: 'a'};
6+
fn(({[foo.bar]: c}) => undefined);
7+
8+
//// [crashInEmitTokenWithComment.js]
9+
// GH#32358
10+
var fn = function (param) { return undefined; };
11+
var foo = { bar: 'a' };
12+
fn(function (_a) {
13+
var _b = foo.bar, c = _a[_b];
14+
return undefined;
15+
});
Collapse file
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @noTypesAndSymbols: true
2+
3+
// GH#32358
4+
const fn = (param: string) => undefined;
5+
6+
const foo = {bar: 'a'};
7+
fn(({[foo.bar]: c}) => undefined);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.