mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-19 10:41:56 -05:00
Preserve module marker in es2015+ module emit for tool compatability (#38712)
This commit is contained in:
@@ -18,25 +18,36 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (isExternalModule(node) || compilerOptions.isolatedModules) {
|
||||
const externalHelpersImportDeclaration = createExternalHelpersImportDeclarationIfNeeded(node, compilerOptions);
|
||||
if (externalHelpersImportDeclaration) {
|
||||
const statements: Statement[] = [];
|
||||
const statementOffset = addPrologue(statements, node.statements);
|
||||
append(statements, externalHelpersImportDeclaration);
|
||||
|
||||
addRange(statements, visitNodes(node.statements, visitor, isStatement, statementOffset));
|
||||
return updateSourceFileNode(
|
||||
node,
|
||||
setTextRange(createNodeArray(statements), node.statements));
|
||||
}
|
||||
else {
|
||||
return visitEachChild(node, visitor, context);
|
||||
const result = updateExternalModule(node);
|
||||
if (!isExternalModule(node) || some(result.statements, isExternalModuleIndicator)) {
|
||||
return result;
|
||||
}
|
||||
return updateSourceFileNode(
|
||||
result,
|
||||
setTextRange(createNodeArray([...result.statements, createEmptyExports()]), result.statements),
|
||||
);
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
function updateExternalModule(node: SourceFile) {
|
||||
const externalHelpersImportDeclaration = createExternalHelpersImportDeclarationIfNeeded(node, compilerOptions);
|
||||
if (externalHelpersImportDeclaration) {
|
||||
const statements: Statement[] = [];
|
||||
const statementOffset = addPrologue(statements, node.statements);
|
||||
append(statements, externalHelpersImportDeclaration);
|
||||
|
||||
addRange(statements, visitNodes(node.statements, visitor, isStatement, statementOffset));
|
||||
return updateSourceFileNode(
|
||||
node,
|
||||
setTextRange(createNodeArray(statements), node.statements));
|
||||
}
|
||||
else {
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
}
|
||||
|
||||
function visitor(node: Node): VisitResult<Node> {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
|
||||
@@ -71,3 +71,4 @@ var M;
|
||||
async function f1() { }
|
||||
M.f1 = f1;
|
||||
})(M || (M = {}));
|
||||
export {};
|
||||
|
||||
@@ -112,3 +112,4 @@ var M;
|
||||
}
|
||||
M.f1 = f1;
|
||||
})(M || (M = {}));
|
||||
export {};
|
||||
|
||||
@@ -65,3 +65,4 @@ class F {
|
||||
}
|
||||
class G {
|
||||
}
|
||||
export {};
|
||||
|
||||
@@ -27,3 +27,4 @@ let Decorated = /** @class */ (() => {
|
||||
})();
|
||||
export default Decorated;
|
||||
//// [undecorated.js]
|
||||
export {};
|
||||
|
||||
@@ -4,3 +4,4 @@ export = a;
|
||||
|
||||
//// [es6ExportAssignment.js]
|
||||
var a = 10;
|
||||
export {};
|
||||
|
||||
@@ -10,4 +10,6 @@ import * as a from "a";
|
||||
|
||||
//// [a.js]
|
||||
var a = 10;
|
||||
export {};
|
||||
//// [b.js]
|
||||
export {};
|
||||
|
||||
@@ -9,3 +9,4 @@ import * as a from "a";
|
||||
|
||||
|
||||
//// [b.js]
|
||||
export {};
|
||||
|
||||
@@ -11,3 +11,4 @@ import * as a from "a";
|
||||
|
||||
|
||||
//// [b.js]
|
||||
export {};
|
||||
|
||||
@@ -9,4 +9,6 @@ import a = require("server");
|
||||
|
||||
//// [server.js]
|
||||
var a = 10;
|
||||
export {};
|
||||
//// [client.js]
|
||||
export {};
|
||||
|
||||
@@ -20,3 +20,4 @@ import {a} from "server";
|
||||
|
||||
|
||||
//// [client.js]
|
||||
export {};
|
||||
|
||||
@@ -17,6 +17,7 @@ var a = /** @class */ (function () {
|
||||
}
|
||||
return a;
|
||||
}());
|
||||
export {};
|
||||
//// [main.js]
|
||||
import * as a from "./a";
|
||||
a;
|
||||
|
||||
@@ -6,3 +6,4 @@ import { default as yield } from "somemodule"; // no error
|
||||
import { default as default } from "somemodule"; // default as is ok, error of default binding name
|
||||
|
||||
//// [es6ImportNamedImportIdentifiersParsing.js]
|
||||
export {};
|
||||
|
||||
@@ -8,6 +8,7 @@ export interface i {
|
||||
import "es6ImportWithoutFromClauseNonInstantiatedModule_0";
|
||||
|
||||
//// [es6ImportWithoutFromClauseNonInstantiatedModule_0.js]
|
||||
export {};
|
||||
//// [es6ImportWithoutFromClauseNonInstantiatedModule_1.js]
|
||||
import "es6ImportWithoutFromClauseNonInstantiatedModule_0";
|
||||
|
||||
|
||||
@@ -7,3 +7,4 @@ namespace N {
|
||||
export = N; // Error
|
||||
|
||||
//// [es6modulekindWithES5Target10.js]
|
||||
export {};
|
||||
|
||||
@@ -7,3 +7,4 @@ namespace N {
|
||||
export = N; // Error
|
||||
|
||||
//// [esnextmodulekindWithES5Target10.js]
|
||||
export {};
|
||||
|
||||
@@ -9,4 +9,6 @@ import bar from './bar';
|
||||
|
||||
//// [bar.js]
|
||||
function bar() { }
|
||||
export {};
|
||||
//// [foo.js]
|
||||
export {};
|
||||
|
||||
@@ -7,3 +7,4 @@ module m {
|
||||
export default m;
|
||||
|
||||
//// [exportDefaultForNonInstantiatedModule.js]
|
||||
export {};
|
||||
|
||||
@@ -11,3 +11,4 @@ var x = import { foo } from './0';
|
||||
export function foo() { return "foo"; }
|
||||
//// [1.js]
|
||||
var x = ;
|
||||
export {};
|
||||
|
||||
@@ -95,6 +95,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
}
|
||||
});
|
||||
}); })();
|
||||
export {};
|
||||
//// [moduleLookingFile01.js]
|
||||
export var x = import.meta;
|
||||
export var y = import.metal;
|
||||
@@ -103,6 +104,7 @@ export var z = import.import.import.malkovich;
|
||||
var globalA = import.meta;
|
||||
var globalB = import.metal;
|
||||
var globalC = import.import.import.malkovich;
|
||||
export {};
|
||||
//// [assignmentTargets.js]
|
||||
export var foo = import.meta.blah = import.meta.blue = import.meta;
|
||||
import.meta = foo;
|
||||
|
||||
@@ -49,6 +49,7 @@ const { a, b, c } = import.meta.wellKnownProperty;
|
||||
image.width = image.height = size;
|
||||
document.body.appendChild(image);
|
||||
})();
|
||||
export {};
|
||||
//// [moduleLookingFile01.js]
|
||||
export let x = import.meta;
|
||||
export let y = import.metal;
|
||||
@@ -57,6 +58,7 @@ export let z = import.import.import.malkovich;
|
||||
let globalA = import.meta;
|
||||
let globalB = import.metal;
|
||||
let globalC = import.import.import.malkovich;
|
||||
export {};
|
||||
//// [assignmentTargets.js]
|
||||
export const foo = import.meta.blah = import.meta.blue = import.meta;
|
||||
import.meta = foo;
|
||||
|
||||
@@ -13,4 +13,6 @@ var Foo = /** @class */ (function () {
|
||||
}
|
||||
return Foo;
|
||||
}());
|
||||
export {};
|
||||
//// [b.js]
|
||||
export {};
|
||||
|
||||
@@ -13,4 +13,6 @@ var Foo = /** @class */ (function () {
|
||||
}
|
||||
return Foo;
|
||||
}());
|
||||
export {};
|
||||
//// [b.js]
|
||||
export {};
|
||||
|
||||
@@ -236,3 +236,4 @@ let obj = {
|
||||
foo(bar) { }
|
||||
};
|
||||
assignPartial(obj, { foo(...args) { } }); // args has type [string]
|
||||
export {};
|
||||
|
||||
@@ -8,5 +8,6 @@ export * from "./a";
|
||||
|
||||
|
||||
//// [a.js]
|
||||
export {};
|
||||
//// [b.js]
|
||||
export * from "./a";
|
||||
|
||||
@@ -217,3 +217,4 @@ let G = /** @class */ (() => {
|
||||
], G);
|
||||
return G;
|
||||
})();
|
||||
export {};
|
||||
|
||||
@@ -15,3 +15,4 @@ import * as b from './b.json';
|
||||
"b": "hello"
|
||||
}
|
||||
//// [out/file1.js]
|
||||
export {};
|
||||
|
||||
@@ -15,3 +15,4 @@ import * as b from './b.json';
|
||||
"b": "hello"
|
||||
}
|
||||
//// [out/file1.js]
|
||||
export {};
|
||||
|
||||
@@ -48,6 +48,7 @@ var \u0079ield = 12; // ok
|
||||
function* gen() {
|
||||
yield 12; //not ok
|
||||
}
|
||||
export {};
|
||||
//// [file2.js]
|
||||
var x = "hello"; // not ok
|
||||
var \u{0061}wait = 12; // ok
|
||||
@@ -59,4 +60,5 @@ function* gen() {
|
||||
yield 12; //not ok
|
||||
}
|
||||
const a = { def\u0061ult: 12 }; // OK, `default` not in keyword position
|
||||
export {};
|
||||
// chrome and jsc may still error on this, ref https://bugs.chromium.org/p/chromium/issues/detail?id=993000 and https://bugs.webkit.org/show_bug.cgi?id=200638
|
||||
|
||||
@@ -6,3 +6,4 @@ import public from "./1"
|
||||
|
||||
//// [strictModeWordInImportDeclaration.js]
|
||||
"use strict";
|
||||
export {};
|
||||
|
||||
@@ -59,3 +59,4 @@ class SomeDerived extends SomeBase {
|
||||
super. `hello world`;
|
||||
}
|
||||
}
|
||||
export {};
|
||||
|
||||
@@ -24,3 +24,4 @@ const Foo = (<h1></h1>);
|
||||
|
||||
//// [foo.jsx]
|
||||
var Foo = (<h1></h1>);
|
||||
export {};
|
||||
|
||||
@@ -21,6 +21,7 @@ React.foo;
|
||||
|
||||
//// [some_module.js]
|
||||
React.foo;
|
||||
export {};
|
||||
//// [emits.js]
|
||||
"use strict";
|
||||
console.log("hello");
|
||||
|
||||
@@ -25,6 +25,7 @@ React.createRef;
|
||||
|
||||
//// [some_module.js]
|
||||
React.createRef;
|
||||
export {};
|
||||
//// [emits.js]
|
||||
"use strict";
|
||||
console.log("hello");
|
||||
|
||||
@@ -105,3 +105,4 @@ let x2 = foo2(sa); // unknown
|
||||
let y2 = foo2(sx); // { extra: number }
|
||||
withRouter(MyComponent);
|
||||
let z = foo(ab); // [AB<string>, string]
|
||||
export {};
|
||||
|
||||
@@ -111,3 +111,4 @@ async function fun(deepPromised) {
|
||||
}
|
||||
}
|
||||
baz(xx);
|
||||
export {};
|
||||
|
||||
Reference in New Issue
Block a user