From 46e4c632ff8a07ded1ba93e9a869e0b78b6bd9d6 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Fri, 25 Mar 2016 18:49:50 -0700 Subject: [PATCH] Fix remaining debug failures. --- Jakefile.js | 124 ++++++++++-------- src/compiler/transformers/es6.ts | 22 +++- src/compiler/transformers/jsx.ts | 22 +++- src/compiler/transformers/module/module.ts | 11 +- src/compiler/transformers/ts.ts | 17 ++- src/compiler/types.ts | 2 +- src/compiler/utilities.ts | 9 +- src/compiler/visitor.ts | 2 +- .../reference/iteratorSpreadInCall12.js | 3 +- .../reference/iteratorSpreadInCall8.js | 3 +- .../reference/iteratorSpreadInCall9.js | 3 +- 11 files changed, 131 insertions(+), 87 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index d024568ee35..53c6bb964b0 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -675,14 +675,24 @@ function cleanTestDirs() { // used to pass data from jake command line directly to run.js function writeTestConfigFile(testConfigFile, tests, light, stackTraceLimit) { - console.log('Running test(s): ' + tests); - var testConfig = { test: [tests], light: light }; - if (/^(\d+|full)$/.test(stackTraceLimit)) { - testConfig.stackTraceLimit = stackTraceLimit; + var testConfig; + if (tests) { + console.log('Running test(s): ' + tests); + (testConfig || (testConfig = {})).tests = [tests]; } - var testConfigContents = JSON.stringify(testConfig); - fs.writeFileSync('test.config', testConfigContents); + if (light) { + (testConfig || (testConfig = {})).light = light; + } + + if (/^(\d+|full)$/.test(stackTraceLimit)) { + (testConfig || (testConfig = {})).stackTraceLimit = stackTraceLimit; + } + + if (testConfig) { + var testConfigContents = JSON.stringify(testConfig); + fs.writeFileSync(testConfigFile, testConfigContents); + } } function deleteTemporaryProjectOutput() { @@ -700,9 +710,7 @@ function runTestsAndWriteOutput(file) { fs.unlinkSync(testConfigFile); } - if (tests || light) { - writeTestConfigFile(testConfigFile, tests, light, 10); - } + writeTestConfigFile(testConfigFile, tests, light, 10); if (tests && tests.toLocaleLowerCase() === "rwc") { testTimeout = 100000; @@ -719,11 +727,16 @@ function runTestsAndWriteOutput(file) { var cmd = "mocha " + args.join(" "); console.log(cmd); - var ex = jake.createExec([cmd], { windowsVerbatimArguments: true }); + var p = child_process.spawn( + process.platform === "win32" ? "cmd" : "/bin/sh", + process.platform === "win32" ? ["/c", cmd] : ["-c", cmd], { + windowsVerbatimArguments: true + }); + var out = fs.createWriteStream(file); var tapRange = /^(\d+)\.\.(\d+)(?:$|\r\n?|\n)/; var tapOk = /^ok\s/; - var tapNotOk = /^not\sok/; + var tapNotOk = /^not\sok\s/; var tapComment = /^#/; var typeError = /^\s+TypeError:/; var debugError = /^\s+Error:\sDebug\sFailure\./; @@ -736,38 +749,9 @@ function runTestsAndWriteOutput(file) { var typeErrorCount = 0; var debugErrorCount = 0; - ex.addListener("stdout", function (output) { - var m = tapRange.exec(output); - if (m) { - expectedTestCount = parseInt(m[2]); - return; - } - - out.write(output); - - if (tapOk.test(output)) { - successCount++; - } - else if (tapNotOk.test(output)) { - failureCount++; - } - else { - if (tapComment.test(output)) { - comments.push(output.toString().trim()); - } - else if (typeError.test(output)) { - typeErrorCount++; - } - else if (debugError.test(output)) { - debugErrorCount++; - } - return; - } - - testCount++; - - var percentComplete = testCount * 100 / expectedTestCount; - updateProgress(percentComplete); + var rl = readline.createInterface({ + input: p.stdout, + terminal: false }); function updateProgress(percentComplete) { @@ -781,22 +765,42 @@ function runTestsAndWriteOutput(file) { ); } - ex.addListener("stderr", function (output) { - progress.hide(); - process.stderr.write(output.toString().trim() + os.EOL); - progress.show(); - }); - ex.addListener("cmdEnd", function () { - if (progress.visible) { - updateProgress(100); - process.stdout.write("done." + os.EOL); + rl.on("line", function (line) { + var m = tapRange.exec(line); + if (m) { + expectedTestCount = parseInt(m[2]); + return; } - console.log(comments.join(os.EOL)); - deleteTemporaryProjectOutput(); - complete(); + if (tapOk.test(line)) { + out.write(line.replace(/^ok\s+\d+\s+/, "ok ") + os.EOL); + successCount++; + } + else if (tapNotOk.test(line)) { + out.write(line.replace(/^not\s+ok\s+\d+\s+/, "not ok ") + os.EOL); + failureCount++; + } + else { + out.write(line + os.EOL); + if (tapComment.test(line)) { + comments.push(line); + } + else if (typeError.test(line)) { + typeErrorCount++; + } + else if (debugError.test(line)) { + debugErrorCount++; + } + return; + } + + testCount++; + + var percentComplete = testCount * 100 / expectedTestCount; + updateProgress(percentComplete); }); - ex.addListener("error", function (e, status) { + + p.on("exit", function (status) { if (progress.visible) { updateProgress(100); process.stdout.write("done." + os.EOL); @@ -813,9 +817,13 @@ function runTestsAndWriteOutput(file) { } deleteTemporaryProjectOutput(); - fail("Process exited with code " + status); + if (status) { + fail("Process exited with code " + status); + } + else { + complete(); + } }); - ex.run(); } function runConsoleTests(defaultReporter, defaultSubsets) { diff --git a/src/compiler/transformers/es6.ts b/src/compiler/transformers/es6.ts index 84213239371..6911730859a 100644 --- a/src/compiler/transformers/es6.ts +++ b/src/compiler/transformers/es6.ts @@ -88,6 +88,9 @@ namespace ts { function visitJavaScript(node: Node): VisitResult { switch (node.kind) { + case SyntaxKind.ExportKeyword: + return node; + case SyntaxKind.ClassDeclaration: return visitClassDeclaration(node); @@ -169,12 +172,19 @@ namespace ts { case SyntaxKind.SuperKeyword: return visitSuperKeyword(node); + case SyntaxKind.YieldExpression: + // `yield` will be handled by a generators transform. + return visitEachChild(node, visitor, context); + case SyntaxKind.MethodDeclaration: return visitMethodDeclaration(node); case SyntaxKind.SourceFile: return visitSourceFileNode(node); + case SyntaxKind.VariableStatement: + return visitEachChild(node, visitor, context); + default: Debug.failBadSyntaxKind(node); return visitEachChild(node, visitor, context); @@ -437,7 +447,11 @@ namespace ts { * @param node A ParameterDeclaration node. */ function visitParameter(node: ParameterDeclaration): ParameterDeclaration { - if (isBindingPattern(node.name)) { + if (node.dotDotDotToken) { + // rest parameters are elided + return undefined; + } + else if (isBindingPattern(node.name)) { // Binding patterns are converted into a generated name and are // evaluated inside the function body. return createParameter( @@ -454,10 +468,6 @@ namespace ts { /*location*/ node ); } - else if (node.dotDotDotToken) { - // rest parameters are elided - return undefined; - } else { return node; } @@ -826,7 +836,7 @@ namespace ts { } const expression = createFunctionExpression( - /*asteriskToken*/ undefined, + node.asteriskToken, name, visitNodes(node.parameters, visitor, isParameter), transformFunctionBody(node), diff --git a/src/compiler/transformers/jsx.ts b/src/compiler/transformers/jsx.ts index dc423e8da7b..6d90415b5e5 100644 --- a/src/compiler/transformers/jsx.ts +++ b/src/compiler/transformers/jsx.ts @@ -38,6 +38,9 @@ namespace ts { case SyntaxKind.JsxSelfClosingElement: return visitJsxSelfClosingElement(node); + case SyntaxKind.JsxExpression: + return visitJsxExpression(node); + default: Debug.failBadSyntaxKind(node); return undefined; @@ -116,12 +119,25 @@ namespace ts { function transformJsxAttributeToObjectLiteralElement(node: JsxAttribute) { const name = getAttributeName(node); - const expression = node.initializer - ? visitNode(node.initializer, visitor, isExpression) - : createLiteral(true); + const expression = transformJsxAttributeInitializer(node.initializer); return createPropertyAssignment(name, expression); } + function transformJsxAttributeInitializer(node: StringLiteral | JsxExpression) { + if (node === undefined) { + return createLiteral(true); + } + else if (node.kind === SyntaxKind.StringLiteral) { + return node; + } + else if (node.kind === SyntaxKind.JsxExpression) { + return visitJsxExpression(node); + } + else { + Debug.failBadSyntaxKind(node); + } + } + function visitJsxText(node: JsxText) { const text = getTextOfNode(node, /*includeTrivia*/ true); let parts: Expression[]; diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 0227ccd8303..107d6446982 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -752,11 +752,12 @@ namespace ts { function createRequireCall(importNode: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration) { const moduleName = getExternalModuleNameLiteral(importNode); - Debug.assert(isDefined(moduleName)); - return createCall( - createIdentifier("require"), - [moduleName] - ); + const args: Expression[] = []; + if (isDefined(moduleName)) { + args.push(moduleName); + } + + return createCall(createIdentifier("require"), args); } function createExportAssignment(name: Identifier, value: Expression) { diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index b127ee50754..8e08ec05796 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -243,14 +243,16 @@ namespace ts { case SyntaxKind.StringKeyword: case SyntaxKind.NumberKeyword: case SyntaxKind.VoidKeyword: + case SyntaxKind.SymbolKeyword: case SyntaxKind.ConstructorType: case SyntaxKind.FunctionType: case SyntaxKind.TypeQuery: case SyntaxKind.TypeReference: case SyntaxKind.UnionType: case SyntaxKind.IntersectionType: - case SyntaxKind.StringLiteralType: + case SyntaxKind.ParenthesizedType: case SyntaxKind.ThisType: + case SyntaxKind.StringLiteralType: // TypeScript type nodes are elided. case SyntaxKind.IndexSignature: @@ -2048,15 +2050,18 @@ namespace ts { * * This function will be called when one of the following conditions are met: * - The node has an accessibility modifier. + * - The node has a questionToken. * * @param node The parameter declaration node. */ function visitParameter(node: ParameterDeclaration) { - Debug.assert(!node.dotDotDotToken); - return createParameter( - visitNode(node.name, visitor, isBindingName), - visitNode(node.initializer, visitor, isExpression) - ); + const clone = getMutableClone(node); + clone.decorators = undefined; + clone.modifiers = undefined; + clone.questionToken = undefined; + clone.type = undefined; + aggregateTransformFlags(clone); + return visitEachChild(clone, visitor, context); } /** diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 09e60035ff3..e54eb596ff0 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1070,7 +1070,7 @@ namespace ts { export interface JsxAttribute extends Node { name: Identifier; /// JSX attribute initializers are optional; is sugar for - initializer?: Expression; + initializer?: StringLiteral | JsxExpression; } // @kind(SyntaxKind.JsxSpreadAttribute) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index aedd44fcb6a..0f788b51b51 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -3408,7 +3408,8 @@ namespace ts { || kind === SyntaxKind.ImportDeclaration || kind === SyntaxKind.ImportEqualsDeclaration || kind === SyntaxKind.ExportDeclaration - || kind === SyntaxKind.ExportAssignment; + || kind === SyntaxKind.ExportAssignment + || kind === SyntaxKind.GlobalModuleExportDeclaration; } function isStatementKindButNotDeclarationKind(kind: SyntaxKind) { @@ -3495,6 +3496,12 @@ namespace ts { return node.kind === SyntaxKind.JsxAttribute; } + export function isStringLiteralOrJsxExpression(node: Node): node is StringLiteral | JsxExpression { + const kind = node.kind; + return kind === SyntaxKind.StringLiteral + || kind === SyntaxKind.JsxExpression; + } + // Clauses export function isCaseOrDefaultClause(node: Node): node is CaseOrDefaultClause { diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index 051c020558a..9739046dba3 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -400,7 +400,7 @@ namespace ts { ], [SyntaxKind.JsxAttribute]: [ { name: "name", test: isIdentifier }, - { name: "initializer", test: isExpression, optional: true }, + { name: "initializer", test: isStringLiteralOrJsxExpression, optional: true }, ], [SyntaxKind.JsxSpreadAttribute]: [ { name: "expression", test: isExpression }, diff --git a/tests/baselines/reference/iteratorSpreadInCall12.js b/tests/baselines/reference/iteratorSpreadInCall12.js index 90b9d9b900b..b138192826d 100644 --- a/tests/baselines/reference/iteratorSpreadInCall12.js +++ b/tests/baselines/reference/iteratorSpreadInCall12.js @@ -34,8 +34,7 @@ class StringIterator { //// [iteratorSpreadInCall12.js] new Foo(...[...new SymbolIterator, ...[...new StringIterator]]); class Foo { - constructor(...s) { - } + constructor(...s) { } } class SymbolIterator { next() { diff --git a/tests/baselines/reference/iteratorSpreadInCall8.js b/tests/baselines/reference/iteratorSpreadInCall8.js index ac22bbcf5a3..3871ff83bc6 100644 --- a/tests/baselines/reference/iteratorSpreadInCall8.js +++ b/tests/baselines/reference/iteratorSpreadInCall8.js @@ -34,8 +34,7 @@ class StringIterator { //// [iteratorSpreadInCall8.js] new Foo(...new SymbolIterator, ...new StringIterator); class Foo { - constructor(...s) { - } + constructor(...s) { } } class SymbolIterator { next() { diff --git a/tests/baselines/reference/iteratorSpreadInCall9.js b/tests/baselines/reference/iteratorSpreadInCall9.js index 2a73ee29c34..da80c461b1b 100644 --- a/tests/baselines/reference/iteratorSpreadInCall9.js +++ b/tests/baselines/reference/iteratorSpreadInCall9.js @@ -34,8 +34,7 @@ class StringIterator { //// [iteratorSpreadInCall9.js] new Foo(...new SymbolIterator, ...[...new StringIterator]); class Foo { - constructor(...s) { - } + constructor(...s) { } } class SymbolIterator { next() {