Merge pull request #7681 from Microsoft/transforms-fixES6ImportElision

Fixes ES6 import elision for transformers
This commit is contained in:
Ron Buckton 2016-03-25 10:20:06 -07:00
commit 6e86b13d46
4 changed files with 54 additions and 7 deletions

View File

@ -695,6 +695,7 @@ function runTestsAndWriteOutput(file) {
cleanTestDirs();
var tests = process.env.test || process.env.tests || process.env.t;
var light = process.env.light || false;
var beep = process.env.beep;
var testConfigFile = 'test.config';
if (fs.existsSync(testConfigFile)) {
fs.unlinkSync(testConfigFile);
@ -726,6 +727,7 @@ function runTestsAndWriteOutput(file) {
var tapNotOk = /^not\sok/;
var tapComment = /^#/;
var typeError = /^\s+TypeError:/;
var debugError = /^\s+Error:\sDebug\sFailure\./;
var progress = new ProgressBar("Running tests...");
var expectedTestCount = 0;
var testCount = 0;
@ -733,6 +735,7 @@ function runTestsAndWriteOutput(file) {
var successCount = 0;
var comments = [];
var typeErrorCount = 0;
var debugErrorCount = 0;
ex.addListener("stdout", function (output) {
var m = tapRange.exec(output);
@ -756,6 +759,9 @@ function runTestsAndWriteOutput(file) {
else if (typeError.test(output)) {
typeErrorCount++;
}
else if (debugError.test(output)) {
debugErrorCount++;
}
return;
}
@ -790,6 +796,8 @@ function runTestsAndWriteOutput(file) {
console.log(comments.join(os.EOL));
deleteTemporaryProjectOutput();
complete();
if (beep) process.stdout.write("\u0007");
});
ex.addListener("error", function (e, status) {
if (progress.visible) {
@ -803,7 +811,12 @@ function runTestsAndWriteOutput(file) {
console.log("# type errors: %s", typeErrorCount);
}
if (debugErrorCount) {
console.log("# debug errors: %s", debugErrorCount);
}
deleteTemporaryProjectOutput();
if (beep) process.stdout.write("\u0007");
fail("Process exited with code " + status);
});
ex.run();

View File

@ -4,9 +4,35 @@
/*@internal*/
namespace ts {
export function transformES6Module(context: TransformationContext) {
const compilerOptions = context.getCompilerOptions();
const resolver = context.getEmitResolver();
let currentSourceFile: SourceFile;
return transformSourceFile;
function transformSourceFile(node: SourceFile) {
if (isExternalModule(node) || compilerOptions.isolatedModules) {
currentSourceFile = node;
return visitEachChild(node, visitor, context);
}
return node;
}
function visitor(node: Node) {
switch (node.kind) {
case SyntaxKind.ImportDeclaration:
return visitImportDeclaration(<ImportDeclaration>node);
}
return node;
}
function visitImportDeclaration(node: ImportDeclaration) {
if (node.importClause && !resolver.isReferencedAliasDeclaration(node.importClause, /*checkChildren*/ true)) {
return undefined;
}
return node;
}
}

View File

@ -1793,11 +1793,14 @@ namespace ts {
return undefined;
}
return createMethod(
visitNodes(node.modifiers, visitor, isModifier),
visitPropertyNameOfClassElement(node),
visitNodes(node.parameters, visitor, isParameter),
transformFunctionBody(node),
return setOriginalNode(
createMethod(
visitNodes(node.modifiers, visitor, isModifier),
visitPropertyNameOfClassElement(node),
visitNodes(node.parameters, visitor, isParameter),
transformFunctionBody(node),
node
),
node
);
}
@ -1900,6 +1903,10 @@ namespace ts {
* @param node The function expression node.
*/
function visitFunctionExpression(node: FunctionExpression) {
if (nodeIsMissing(node.body)) {
return createNode(SyntaxKind.OmittedExpression);
}
return createFunctionExpression(
node.asteriskToken,
node.name,
@ -1916,7 +1923,7 @@ namespace ts {
* @param node The declaration node.
*/
function shouldElideFunctionLikeDeclaration(node: FunctionLikeDeclaration) {
return node.body === undefined
return nodeIsMissing(node.body)
|| hasModifier(node, ModifierFlags.Abstract | ModifierFlags.Ambient);
}
@ -2004,7 +2011,7 @@ namespace ts {
)
);
const block = createBlock(statements, /*location*/ node.body);
const block = createBlock(statements, /*location*/ node.body, /*multiLine*/ true);
// Minor optimization, emit `_super` helper to capture `super` access in an arrow.
// This step isn't needed if we eventually transform this to ES5.

View File

@ -3405,6 +3405,7 @@ namespace ts {
|| kind === SyntaxKind.TypeAliasDeclaration
|| kind === SyntaxKind.EnumDeclaration
|| kind === SyntaxKind.ModuleDeclaration
|| kind === SyntaxKind.ImportDeclaration
|| kind === SyntaxKind.ImportEqualsDeclaration
|| kind === SyntaxKind.ExportDeclaration
|| kind === SyntaxKind.ExportAssignment;