hoist-unmodified-var
Ben McCann 9 months ago
parent c53ae0c600
commit 2169608d89

@ -7,6 +7,7 @@ import {
PROPS_IS_RUNES,
PROPS_IS_UPDATED
} from '../../../../constants.js';
import { GlobalBindings } from '../../constants.js';
/**
* @template {import('./types').ClientTransformState} State
@ -548,6 +549,8 @@ export function is_hoistable_declaration(binding, name) {
!binding.mutated &&
!binding.reassigned &&
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 { error } from '../errors.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 {
/** @type {ScopeRoot} */
@ -127,6 +127,11 @@ export class Scope {
return binding;
}
/** @returns {boolean} */
has_parent() {
return this.#parent !== null;
}
/**
* @param {string} name
* @returns {boolean}
@ -139,7 +144,7 @@ export class Scope {
}
outer = outer.#parent;
}
return GlobalBindings.has(name) || JsKeywords.includes(name);
return false;
}
child(porous = false) {

Loading…
Cancel
Save