Skip to content

Commit

Permalink
fix: bump is-reference dependency to fix import.meta bug (#14286)
Browse files Browse the repository at this point in the history
closes #14234
  • Loading branch information
dummdidumm authored Nov 14, 2024
1 parent 45fa678 commit 320ebd2
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/shaggy-flowers-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: bump `is-reference` dependency to fix `import.meta` bug
2 changes: 1 addition & 1 deletion packages/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
"axobject-query": "^4.1.0",
"esm-env": "^1.0.0",
"esrap": "^1.2.2",
"is-reference": "^3.0.2",
"is-reference": "^3.0.3",
"locate-character": "^3.0.0",
"magic-string": "^0.30.11",
"zimmerframe": "^1.1.2"
Expand Down
3 changes: 3 additions & 0 deletions packages/svelte/src/compiler/migrate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ const instance_script = {
for (let specifier of node.specifiers) {
if (
specifier.type === 'ImportSpecifier' &&
specifier.imported.type === 'Identifier' &&
['beforeUpdate', 'afterUpdate'].includes(specifier.imported.name)
) {
const references = state.scope.references.get(specifier.local.name);
Expand Down Expand Up @@ -544,6 +545,8 @@ const instance_script = {

let count_removed = 0;
for (const specifier of node.specifiers) {
if (specifier.local.type !== 'Identifier') continue;

const binding = state.scope.get(specifier.local.name);
if (binding?.kind === 'bindable_prop') {
state.str.remove(
Expand Down
4 changes: 4 additions & 0 deletions packages/svelte/src/compiler/phases/2-analyze/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,10 @@ export function analyze_component(root, source, options) {
}
} else {
for (const specifier of node.specifiers) {
if (specifier.local.type !== 'Identifier' || specifier.exported.type !== 'Identifier') {
continue;
}

const binding = instance.scope.get(specifier.local.name);

if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export function ExportNamedDeclaration(node, context) {

if (!context.state.ast_type /* .svelte.js module */ || context.state.ast_type === 'module') {
for (const specified of node.specifiers) {
if (specified.local.type !== 'Identifier') continue;

const binding = context.state.scope.get(specified.local.name);

if (!binding) continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,25 @@ import * as e from '../../../errors.js';
* @param {Context} context
*/
export function ExportSpecifier(node, context) {
const local_name =
node.local.type === 'Identifier' ? node.local.name : /** @type {string} */ (node.local.value);
const exported_name =
node.exported.type === 'Identifier'
? node.exported.name
: /** @type {string} */ (node.exported.value);

if (context.state.ast_type === 'instance') {
if (context.state.analysis.runes) {
context.state.analysis.exports.push({
name: node.local.name,
alias: node.exported.name
name: local_name,
alias: exported_name
});

const binding = context.state.scope.get(node.local.name);
const binding = context.state.scope.get(local_name);
if (binding) binding.reassigned = binding.updated = true;
}
} else {
validate_export(node, context.state.scope, node.local.name);
validate_export(node, context.state.scope, local_name);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ export function ImportDeclaration(node, context) {
for (const specifier of node.specifiers) {
if (specifier.type === 'ImportSpecifier') {
if (
specifier.imported.name === 'beforeUpdate' ||
specifier.imported.name === 'afterUpdate'
specifier.imported.type === 'Identifier' &&
(specifier.imported.name === 'beforeUpdate' ||
specifier.imported.name === 'afterUpdate')
) {
e.runes_mode_invalid_import(specifier, specifier.imported.name);
}
Expand Down
11 changes: 9 additions & 2 deletions packages/svelte/src/compiler/utils/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,11 @@ export function is_simple_expression(node) {
}

if (node.type === 'BinaryExpression' || node.type === 'LogicalExpression') {
return is_simple_expression(node.left) && is_simple_expression(node.right);
return (
node.left.type !== 'PrivateIdentifier' &&
is_simple_expression(node.left) &&
is_simple_expression(node.right)
);
}

return false;
Expand Down Expand Up @@ -475,7 +479,10 @@ export function is_expression_async(expression) {
case 'AssignmentExpression':
case 'BinaryExpression':
case 'LogicalExpression': {
return is_expression_async(expression.left) || is_expression_async(expression.right);
return (
(expression.left.type !== 'PrivateIdentifier' && is_expression_async(expression.left)) ||
is_expression_async(expression.right)
);
}
case 'CallExpression':
case 'NewExpression': {
Expand Down
5 changes: 2 additions & 3 deletions packages/svelte/src/compiler/utils/builders.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export function prop(kind, key, value, computed = false) {
* @returns {ESTree.PropertyDefinition}
*/
export function prop_def(key, value, computed = false, is_static = false) {
return { type: 'PropertyDefinition', key, value, computed, static: is_static, decorators: [] };
return { type: 'PropertyDefinition', key, value, computed, static: is_static };
}

/**
Expand Down Expand Up @@ -551,8 +551,7 @@ export function method(kind, key, params, body, computed = false, is_static = fa
kind,
value: function_builder(null, params, block(body)),
computed,
static: is_static,
decorators: []
static: is_static
};
}

Expand Down
29 changes: 17 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 320ebd2

Please sign in to comment.