hoist-unmodified-var
Ben McCann 2 years ago
parent c53ae0c600
commit 2169608d89

@ -7,6 +7,7 @@ import {
PROPS_IS_RUNES, PROPS_IS_RUNES,
PROPS_IS_UPDATED PROPS_IS_UPDATED
} from '../../../../constants.js'; } from '../../../../constants.js';
import { GlobalBindings } from '../../constants.js';
/** /**
* @template {import('./types').ClientTransformState} State * @template {import('./types').ClientTransformState} State
@ -548,6 +549,8 @@ export function is_hoistable_declaration(binding, name) {
!binding.mutated && !binding.mutated &&
!binding.reassigned && !binding.reassigned &&
binding.initial?.type === 'Literal' && binding.initial?.type === 'Literal' &&
!binding.scope.declared_in_outer_scope(name) binding.scope.has_parent() && // i.e. not when context="module"
!binding.scope.declared_in_outer_scope(name) &&
!GlobalBindings.has(name)
); );
} }

@ -4,7 +4,7 @@ import { is_element_node } from './nodes.js';
import * as b from '../utils/builders.js'; import * as b from '../utils/builders.js';
import { error } from '../errors.js'; import { error } from '../errors.js';
import { extract_identifiers, extract_identifiers_from_expression } from '../utils/ast.js'; import { extract_identifiers, extract_identifiers_from_expression } from '../utils/ast.js';
import { GlobalBindings, JsKeywords, Runes } from './constants.js'; import { JsKeywords, Runes } from './constants.js';
export class Scope { export class Scope {
/** @type {ScopeRoot} */ /** @type {ScopeRoot} */
@ -127,6 +127,11 @@ export class Scope {
return binding; return binding;
} }
/** @returns {boolean} */
has_parent() {
return this.#parent !== null;
}
/** /**
* @param {string} name * @param {string} name
* @returns {boolean} * @returns {boolean}
@ -139,7 +144,7 @@ export class Scope {
} }
outer = outer.#parent; outer = outer.#parent;
} }
return GlobalBindings.has(name) || JsKeywords.includes(name); return false;
} }
child(porous = false) { child(porous = false) {

Loading…
Cancel
Save