Skip to content

Commit af89255

Browse files
committed
addressed PR feedback
1 parent b1cc06e commit af89255

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/compiler/emitter.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -1950,7 +1950,7 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
19501950
? <Declaration>node.parent
19511951
: resolver.getReferencedValueDeclaration(<Identifier>node);
19521952

1953-
return isSourceFileLevelDeclarationInSystemExternalModule(targetDeclaration, /*isExported*/ true);
1953+
return isSourceFileLevelDeclarationInSystemJsModule(targetDeclaration, /*isExported*/ true);
19541954
}
19551955

19561956
function emitPrefixUnaryExpression(node: PrefixUnaryExpression) {
@@ -2021,6 +2021,10 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
20212021
}
20222022
}
20232023

2024+
function shouldHoistDeclarationInSystemJsModule(node: Node): boolean {
2025+
return isSourceFileLevelDeclarationInSystemJsModule(node, /*isExported*/ false);
2026+
}
2027+
20242028
/*
20252029
* Checks if given node is a source file level declaration (not nested in module/function).
20262030
* If 'isExported' is true - then declaration must also be exported.
@@ -2031,7 +2035,7 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
20312035
* i.e non-exported variable statement 'var x = 1' is hoisted so
20322036
* we we emit variable statement 'var' should be dropped.
20332037
*/
2034-
function isSourceFileLevelDeclarationInSystemExternalModule(node: Node, isExported: boolean): boolean {
2038+
function isSourceFileLevelDeclarationInSystemJsModule(node: Node, isExported: boolean): boolean {
20352039
if (!node || languageVersion >= ScriptTarget.ES6 || !isCurrentFileSystemExternalModule()) {
20362040
return false;
20372041
}
@@ -2682,7 +2686,7 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
26822686
let canDefineTempVariablesInPlace = false;
26832687
if (root.kind === SyntaxKind.VariableDeclaration) {
26842688
let isExported = getCombinedNodeFlags(root) & NodeFlags.Export;
2685-
let isSourceLevelForSystemModuleKind = isSourceFileLevelDeclarationInSystemExternalModule(root, /*isExported*/ false);
2689+
let isSourceLevelForSystemModuleKind = shouldHoistDeclarationInSystemJsModule(root);
26862690
canDefineTempVariablesInPlace = !isExported && !isSourceLevelForSystemModuleKind;
26872691
}
26882692
else if (root.kind === SyntaxKind.Parameter) {
@@ -3938,7 +3942,7 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
39383942
function emitClassLikeDeclarationBelowES6(node: ClassLikeDeclaration) {
39393943
if (node.kind === SyntaxKind.ClassDeclaration) {
39403944
// source file level classes in system modules are hoisted so 'var's for them are already defined
3941-
if (!isSourceFileLevelDeclarationInSystemExternalModule(node, /*isExported*/ false)) {
3945+
if (!shouldHoistDeclarationInSystemJsModule(node)) {
39423946
write("var ");
39433947
}
39443948
emitDeclarationName(node);
@@ -4450,7 +4454,7 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
44504454
if (!shouldEmit) {
44514455
return emitOnlyPinnedOrTripleSlashComments(node);
44524456
}
4453-
let hoistedInDeclarationScope = isSourceFileLevelDeclarationInSystemExternalModule(node, /*isExported*/ false);
4457+
let hoistedInDeclarationScope = shouldHoistDeclarationInSystemJsModule(node);
44544458
let emitVarForModule = !hoistedInDeclarationScope && !isModuleMergedWithES6Class(node);
44554459

44564460
if (emitVarForModule) {
@@ -5034,7 +5038,7 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
50345038
}
50355039

50365040
function shouldHoistVariable(node: VariableDeclaration | VariableDeclarationList | BindingElement, checkIfSourceFileLevelDecl: boolean): boolean {
5037-
if (checkIfSourceFileLevelDecl && !isSourceFileLevelDeclarationInSystemExternalModule(node, /*isExported*/ false)) {
5041+
if (checkIfSourceFileLevelDecl && !shouldHoistDeclarationInSystemJsModule(node)) {
50385042
return false;
50395043
}
50405044
// hoist variable if

0 commit comments

Comments
 (0)