From 89545995923c96dce3a19cf4c23930548c68491b Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 19 Apr 2016 18:07:27 -0700 Subject: [PATCH 1/2] Fix debug failure in parser --- src/compiler/utilities.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 7e393c5a35a..31e4277f75f 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -509,7 +509,7 @@ namespace ts { const { line: startLine } = getLineAndCharacterOfPosition(sourceFile, node.body.pos); const { line: endLine } = getLineAndCharacterOfPosition(sourceFile, node.body.end); if (startLine < endLine) { - // The arrow function spans multiple lines, + // The arrow function spans multiple lines, // make the error span be the first line, inclusive. return createTextSpan(pos, getEndLinePosition(startLine, sourceFile) - pos + 1); } @@ -3462,7 +3462,8 @@ namespace ts { || kind === SyntaxKind.NullKeyword || kind === SyntaxKind.ThisKeyword || kind === SyntaxKind.TrueKeyword - || kind === SyntaxKind.SuperKeyword; + || kind === SyntaxKind.SuperKeyword + || kind === SyntaxKind.NonNullExpression; } export function isLeftHandSideExpression(node: Node): node is LeftHandSideExpression { From 0d6ff81d5ad1235bc5424b2f01b1b9305979dc93 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 19 Apr 2016 18:16:46 -0700 Subject: [PATCH 2/2] Adds transforms for NonNullExpression --- src/compiler/binder.ts | 1 + src/compiler/printer.ts | 7 +++++++ src/compiler/transformers/ts.ts | 11 ++++++++++- src/compiler/visitor.ts | 3 +++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 0d9002a1ddb..af903d72077 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1883,6 +1883,7 @@ namespace ts { case SyntaxKind.EnumMember: case SyntaxKind.TypeAssertionExpression: case SyntaxKind.AsExpression: + case SyntaxKind.NonNullExpression: case SyntaxKind.ReadonlyKeyword: // These nodes are TypeScript syntax. transformFlags = TransformFlags.AssertTypeScript; diff --git a/src/compiler/printer.ts b/src/compiler/printer.ts index 2410785d897..501b03425df 100644 --- a/src/compiler/printer.ts +++ b/src/compiler/printer.ts @@ -751,6 +751,8 @@ const _super = (function (geti, seti) { return; case SyntaxKind.AsExpression: return emitAsExpression(node); + case SyntaxKind.NonNullExpression: + return emitNonNullExpression(node); // JSX case SyntaxKind.JsxElement: @@ -1286,6 +1288,11 @@ const _super = (function (geti, seti) { } } + function emitNonNullExpression(node: NonNullExpression) { + emitExpression(node.expression); + write("!"); + } + // // Misc // diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 9f13f2b64ba..a493deb35c4 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -371,6 +371,10 @@ namespace ts { // TypeScript type assertions are removed, but their subtrees are preserved. return visitAssertionExpression(node); + case SyntaxKind.NonNullExpression: + // TypeScript non-null expressions are removed, but their subtrees are preserved. + return visitNonNullExpression(node); + case SyntaxKind.EnumDeclaration: // TypeScript enum declarations do not exist in ES6 and must be rewritten. return visitEnumDeclaration(node); @@ -2228,7 +2232,12 @@ namespace ts { } function visitAssertionExpression(node: AssertionExpression): Expression { - const expression = visitNode((node).expression, visitor, isExpression); + const expression = visitNode(node.expression, visitor, isExpression); + return createPartiallyEmittedExpression(expression, node); + } + + function visitNonNullExpression(node: NonNullExpression): Expression { + const expression = visitNode(node.expression, visitor, isLeftHandSideExpression); return createPartiallyEmittedExpression(expression, node); } diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index d55357bed8d..525761df5c3 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -219,6 +219,9 @@ namespace ts { { name: "expression", test: isExpression }, { name: "type", test: isTypeNode } ], + [SyntaxKind.NonNullExpression]: [ + { name: "expression", test: isLeftHandSideExpression } + ], [SyntaxKind.TemplateSpan]: [ { name: "expression", test: isExpression }, { name: "literal", test: isTemplateLiteralFragment }