Fix crash in emitTokenWithComment (#36542)

This commit is contained in:
Ron Buckton 2020-01-31 10:41:09 -08:00 committed by GitHub
parent 80ad0de87e
commit 24d8f795b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 3 deletions

View File

@ -2744,11 +2744,11 @@ namespace ts {
const node = getParseTreeNode(contextNode);
const isSimilarNode = node && node.kind === contextNode.kind;
const startPos = pos;
if (isSimilarNode) {
pos = skipTrivia(currentSourceFile!.text, pos);
if (isSimilarNode && currentSourceFile) {
pos = skipTrivia(currentSourceFile.text, pos);
}
if (emitLeadingCommentsOfPosition && isSimilarNode && contextNode.pos !== startPos) {
const needsIndent = indentLeading && !positionsAreOnSameLine(startPos, pos, currentSourceFile!);
const needsIndent = indentLeading && currentSourceFile && !positionsAreOnSameLine(startPos, pos, currentSourceFile);
if (needsIndent) {
increaseIndent();
}

View File

@ -0,0 +1,14 @@
tests/cases/compiler/crashInEmitTokenWithComment.ts(5,4): error TS2345: Argument of type '({ [foo.bar]: c }: {}) => any' is not assignable to parameter of type 'string'.
tests/cases/compiler/crashInEmitTokenWithComment.ts(5,7): error TS2537: Type '{}' has no matching index signature for type 'string'.
==== tests/cases/compiler/crashInEmitTokenWithComment.ts (2 errors) ====
// GH#32358
const fn = (param: string) => undefined;
const foo = {bar: 'a'};
fn(({[foo.bar]: c}) => undefined);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '({ [foo.bar]: c }: {}) => any' is not assignable to parameter of type 'string'.
~~~~~~~
!!! error TS2537: Type '{}' has no matching index signature for type 'string'.

View File

@ -0,0 +1,15 @@
//// [crashInEmitTokenWithComment.ts]
// GH#32358
const fn = (param: string) => undefined;
const foo = {bar: 'a'};
fn(({[foo.bar]: c}) => undefined);
//// [crashInEmitTokenWithComment.js]
// GH#32358
var fn = function (param) { return undefined; };
var foo = { bar: 'a' };
fn(function (_a) {
var _b = foo.bar, c = _a[_b];
return undefined;
});

View File

@ -0,0 +1,7 @@
// @noTypesAndSymbols: true
// GH#32358
const fn = (param: string) => undefined;
const foo = {bar: 'a'};
fn(({[foo.bar]: c}) => undefined);