Fix issue where var declarations aren't in a block

pull/8442/head
Nguyen Tran 3 years ago
parent 7352b2d902
commit 915b8b194e

@ -25,7 +25,7 @@ import TemplateScope from './nodes/shared/TemplateScope';
import fuzzymatch from '../utils/fuzzymatch'; import fuzzymatch from '../utils/fuzzymatch';
import get_object from './utils/get_object'; import get_object from './utils/get_object';
import Slot from './nodes/Slot'; import Slot from './nodes/Slot';
import { Node, ImportDeclaration, ExportNamedDeclaration, Identifier, ExpressionStatement, AssignmentExpression, Literal, Property, RestElement, ExportDefaultDeclaration, ExportAllDeclaration, FunctionDeclaration, FunctionExpression } from 'estree'; import { Node, ImportDeclaration, ExportNamedDeclaration, Identifier, ExpressionStatement, AssignmentExpression, Literal, Property, RestElement, ExportDefaultDeclaration, ExportAllDeclaration, FunctionDeclaration, FunctionExpression, Statement } from 'estree';
import add_to_set from './utils/add_to_set'; import add_to_set from './utils/add_to_set';
import check_graph_for_cycles from './utils/check_graph_for_cycles'; import check_graph_for_cycles from './utils/check_graph_for_cycles';
import { print, b } from 'code-red'; import { print, b } from 'code-red';
@ -38,6 +38,7 @@ import compiler_warnings from './compiler_warnings';
import compiler_errors from './compiler_errors'; import compiler_errors from './compiler_errors';
import { extract_ignores_above_position, extract_svelte_ignore_from_comments } from '../utils/extract_svelte_ignore'; import { extract_ignores_above_position, extract_svelte_ignore_from_comments } from '../utils/extract_svelte_ignore';
import check_enable_sourcemap from './utils/check_enable_sourcemap'; import check_enable_sourcemap from './utils/check_enable_sourcemap';
import { flatten } from '../utils/flatten';
interface ComponentOptions { interface ComponentOptions {
namespace?: string; namespace?: string;
@ -1138,14 +1139,23 @@ export default class Component {
} }
} }
if (inserts.length > 0) { if (Array.isArray(parent[key])) {
parent[key].splice(index + 1, 0, ...inserts); if (inserts.length > 0) {
} inserts.reverse().forEach((insert) => {
if (props.length > 0) { parent[key].splice(index + 1, 0, ...insert);
parent[key].splice(index + 1, 0, b`let { ${props} } = $$props;`); });
} }
if (node.declarations.length == 0) { if (props.length > 0) {
parent[key].splice(index, 1); parent[key].splice(index + 1, 0, b`let { ${props} } = $$props;`);
}
if (node.declarations.length == 0) {
parent[key].splice(index, 1);
}
} else if (inserts.length > 0) {
this.replace({
type: 'BlockStatement',
body: flatten([node, inserts]) as Statement[]
});
} }
return this.skip(); return this.skip();

Loading…
Cancel
Save