Skip to content

Commit 5c7b867

Browse files
committed
fix types
1 parent f558694 commit 5c7b867

File tree

7 files changed

+34
-11
lines changed

7 files changed

+34
-11
lines changed

packages/svelte/src/compiler/migrate/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ const instance_script = {
507507
for (let specifier of node.specifiers) {
508508
if (
509509
specifier.type === 'ImportSpecifier' &&
510+
specifier.imported.type === 'Identifier' &&
510511
['beforeUpdate', 'afterUpdate'].includes(specifier.imported.name)
511512
) {
512513
const references = state.scope.references.get(specifier.local.name);
@@ -544,6 +545,8 @@ const instance_script = {
544545

545546
let count_removed = 0;
546547
for (const specifier of node.specifiers) {
548+
if (specifier.local.type !== 'Identifier') continue;
549+
547550
const binding = state.scope.get(specifier.local.name);
548551
if (binding?.kind === 'bindable_prop') {
549552
state.str.remove(

packages/svelte/src/compiler/phases/2-analyze/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,10 @@ export function analyze_component(root, source, options) {
474474
}
475475
} else {
476476
for (const specifier of node.specifiers) {
477+
if (specifier.local.type !== 'Identifier' || specifier.exported.type !== 'Identifier') {
478+
continue;
479+
}
480+
477481
const binding = instance.scope.get(specifier.local.name);
478482

479483
if (

packages/svelte/src/compiler/phases/2-analyze/visitors/ExportNamedDeclaration.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ export function ExportNamedDeclaration(node, context) {
6060

6161
if (!context.state.ast_type /* .svelte.js module */ || context.state.ast_type === 'module') {
6262
for (const specified of node.specifiers) {
63+
if (specified.local.type !== 'Identifier') continue;
64+
6365
const binding = context.state.scope.get(specified.local.name);
6466

6567
if (!binding) continue;

packages/svelte/src/compiler/phases/2-analyze/visitors/ExportSpecifier.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,25 @@ import * as e from '../../../errors.js';
99
* @param {Context} context
1010
*/
1111
export function ExportSpecifier(node, context) {
12+
const local_name =
13+
node.local.type === 'Identifier' ? node.local.name : /** @type {string} */ (node.local.value);
14+
const exported_name =
15+
node.exported.type === 'Identifier'
16+
? node.exported.name
17+
: /** @type {string} */ (node.exported.value);
18+
1219
if (context.state.ast_type === 'instance') {
1320
if (context.state.analysis.runes) {
1421
context.state.analysis.exports.push({
15-
name: node.local.name,
16-
alias: node.exported.name
22+
name: local_name,
23+
alias: exported_name
1724
});
1825

19-
const binding = context.state.scope.get(node.local.name);
26+
const binding = context.state.scope.get(local_name);
2027
if (binding) binding.reassigned = binding.updated = true;
2128
}
2229
} else {
23-
validate_export(node, context.state.scope, node.local.name);
30+
validate_export(node, context.state.scope, local_name);
2431
}
2532
}
2633

packages/svelte/src/compiler/phases/2-analyze/visitors/ImportDeclaration.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ export function ImportDeclaration(node, context) {
1818
for (const specifier of node.specifiers) {
1919
if (specifier.type === 'ImportSpecifier') {
2020
if (
21-
specifier.imported.name === 'beforeUpdate' ||
22-
specifier.imported.name === 'afterUpdate'
21+
specifier.imported.type === 'Identifier' &&
22+
(specifier.imported.name === 'beforeUpdate' ||
23+
specifier.imported.name === 'afterUpdate')
2324
) {
2425
e.runes_mode_invalid_import(specifier, specifier.imported.name);
2526
}

packages/svelte/src/compiler/utils/ast.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,11 @@ export function is_simple_expression(node) {
433433
}
434434

435435
if (node.type === 'BinaryExpression' || node.type === 'LogicalExpression') {
436-
return is_simple_expression(node.left) && is_simple_expression(node.right);
436+
return (
437+
node.left.type !== 'PrivateIdentifier' &&
438+
is_simple_expression(node.left) &&
439+
is_simple_expression(node.right)
440+
);
437441
}
438442

439443
return false;
@@ -475,7 +479,10 @@ export function is_expression_async(expression) {
475479
case 'AssignmentExpression':
476480
case 'BinaryExpression':
477481
case 'LogicalExpression': {
478-
return is_expression_async(expression.left) || is_expression_async(expression.right);
482+
return (
483+
(expression.left.type !== 'PrivateIdentifier' && is_expression_async(expression.left)) ||
484+
is_expression_async(expression.right)
485+
);
479486
}
480487
case 'CallExpression':
481488
case 'NewExpression': {

packages/svelte/src/compiler/utils/builders.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ export function prop(kind, key, value, computed = false) {
350350
* @returns {ESTree.PropertyDefinition}
351351
*/
352352
export function prop_def(key, value, computed = false, is_static = false) {
353-
return { type: 'PropertyDefinition', key, value, computed, static: is_static, decorators: [] };
353+
return { type: 'PropertyDefinition', key, value, computed, static: is_static };
354354
}
355355

356356
/**
@@ -551,8 +551,7 @@ export function method(kind, key, params, body, computed = false, is_static = fa
551551
kind,
552552
value: function_builder(null, params, block(body)),
553553
computed,
554-
static: is_static,
555-
decorators: []
554+
static: is_static
556555
};
557556
}
558557

0 commit comments

Comments
 (0)