Handle synthetic nodes correctly as namespace identifiers in system transform (#19623)
* Handle synthetic nodes correctly as namespace identifiers in system transform * Add ref to issue in comment * Lock newline for ci
This commit is contained in:
parent
e9841f3899
commit
235356e6ff
3 changed files with 46 additions and 1 deletions
|
@ -4319,7 +4319,7 @@ namespace ts {
|
|||
const namespaceDeclaration = getNamespaceDeclarationNode(node);
|
||||
if (namespaceDeclaration && !isDefaultImport(node)) {
|
||||
const name = namespaceDeclaration.name;
|
||||
return isGeneratedIdentifier(name) ? name : createIdentifier(getSourceTextOfNodeFromSourceFile(sourceFile, namespaceDeclaration.name));
|
||||
return isGeneratedIdentifier(name) ? name : createIdentifier(getSourceTextOfNodeFromSourceFile(sourceFile, name) || idText(name));
|
||||
}
|
||||
if (node.kind === SyntaxKind.ImportDeclaration && (<ImportDeclaration>node).importClause) {
|
||||
return getGeneratedNameForNode(node);
|
||||
|
|
|
@ -192,6 +192,38 @@ namespace ts {
|
|||
};
|
||||
}
|
||||
});
|
||||
|
||||
// https://github.com/Microsoft/TypeScript/issues/19618
|
||||
testBaseline("transformAddImportStar", () => {
|
||||
return ts.transpileModule("", {
|
||||
transformers: {
|
||||
before: [transformAddImportStar],
|
||||
},
|
||||
compilerOptions: {
|
||||
target: ts.ScriptTarget.ES5,
|
||||
module: ts.ModuleKind.System,
|
||||
newLine: NewLineKind.CarriageReturnLineFeed,
|
||||
}
|
||||
}).outputText;
|
||||
|
||||
function transformAddImportStar(_context: ts.TransformationContext) {
|
||||
return (sourceFile: ts.SourceFile): ts.SourceFile => {
|
||||
return visitNode(sourceFile);
|
||||
};
|
||||
function visitNode(sf: ts.SourceFile) {
|
||||
// produce `import * as i0 from './comp';
|
||||
const importStar = ts.createImportDeclaration(
|
||||
/*decorators*/ undefined,
|
||||
/*modifiers*/ undefined,
|
||||
/*importClause*/ ts.createImportClause(
|
||||
/*name*/ undefined,
|
||||
ts.createNamespaceImport(ts.createIdentifier("i0"))
|
||||
),
|
||||
/*moduleSpecifier*/ ts.createLiteral("./comp1"));
|
||||
return ts.updateSourceFileNode(sf, [importStar]);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
System.register(["./comp1"], function (exports_1, context_1) {
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
var i0;
|
||||
return {
|
||||
setters: [
|
||||
function (i0_1) {
|
||||
i0 = i0_1;
|
||||
}
|
||||
],
|
||||
execute: function () {
|
||||
}
|
||||
};
|
||||
});
|
Loading…
Reference in a new issue