|
|
|
@ -265,7 +265,7 @@ export default class Component {
|
|
|
|
|
);
|
|
|
|
|
this.walk_instance_js_post_template();
|
|
|
|
|
this.pop_ignores();
|
|
|
|
|
this.elements.forEach(/** @param {any} element */ (element) => this.stylesheet.apply(element));
|
|
|
|
|
this.elements.forEach((element) => this.stylesheet.apply(element));
|
|
|
|
|
this.stylesheet.reify();
|
|
|
|
|
this.stylesheet.warn_on_unused_selectors(this);
|
|
|
|
|
}
|
|
|
|
@ -405,19 +405,15 @@ export default class Component {
|
|
|
|
|
});
|
|
|
|
|
const referenced_globals = Array.from(
|
|
|
|
|
this.globals,
|
|
|
|
|
/** @param {any}params_0 */
|
|
|
|
|
([name, alias]) => name !== alias.name && { name, alias }
|
|
|
|
|
).filter(Boolean);
|
|
|
|
|
if (referenced_globals.length) {
|
|
|
|
|
this.helpers.set('globals', this.alias('globals'));
|
|
|
|
|
}
|
|
|
|
|
const imported_helpers = Array.from(
|
|
|
|
|
this.helpers,
|
|
|
|
|
/** @param {any}params_0 */ ([name, alias]) => ({
|
|
|
|
|
const imported_helpers = Array.from(this.helpers, ([name, alias]) => ({
|
|
|
|
|
name,
|
|
|
|
|
alias
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}));
|
|
|
|
|
create_module(
|
|
|
|
|
program,
|
|
|
|
|
name,
|
|
|
|
@ -427,15 +423,11 @@ export default class Component {
|
|
|
|
|
referenced_globals,
|
|
|
|
|
this.imports,
|
|
|
|
|
this.vars
|
|
|
|
|
.filter(
|
|
|
|
|
/** @param {any} variable */ (variable) => variable.module && variable.export_name
|
|
|
|
|
)
|
|
|
|
|
.map(
|
|
|
|
|
/** @param {any} variable */ (variable) => ({
|
|
|
|
|
.filter((variable) => variable.module && variable.export_name)
|
|
|
|
|
.map((variable) => ({
|
|
|
|
|
name: variable.name,
|
|
|
|
|
as: variable.export_name
|
|
|
|
|
})
|
|
|
|
|
),
|
|
|
|
|
})),
|
|
|
|
|
this.exports_from
|
|
|
|
|
);
|
|
|
|
|
css = compile_options.customElement ? { code: null, map: null } : result.css;
|
|
|
|
@ -499,12 +491,7 @@ export default class Component {
|
|
|
|
|
}
|
|
|
|
|
reserved.forEach(add);
|
|
|
|
|
internal_exports.forEach(add);
|
|
|
|
|
this.var_lookup.forEach(
|
|
|
|
|
/**
|
|
|
|
|
* @param {any} _value
|
|
|
|
|
* @param {any} key
|
|
|
|
|
*/ (_value, key) => add(key)
|
|
|
|
|
);
|
|
|
|
|
this.var_lookup.forEach((_value, key) => add(key));
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {string} name
|
|
|
|
@ -534,9 +521,8 @@ export default class Component {
|
|
|
|
|
? []
|
|
|
|
|
: compile_options.varsReport === 'full'
|
|
|
|
|
? vars
|
|
|
|
|
: vars.filter(/** @param {any} v */ (v) => !v.global && !v.internal);
|
|
|
|
|
return vars_report.map(
|
|
|
|
|
/** @param {any} v */ (v) => ({
|
|
|
|
|
: vars.filter((v) => !v.global && !v.internal);
|
|
|
|
|
return vars_report.map((v) => ({
|
|
|
|
|
name: v.name,
|
|
|
|
|
export_name: v.export_name || null,
|
|
|
|
|
injected: v.injected || false,
|
|
|
|
@ -546,8 +532,7 @@ export default class Component {
|
|
|
|
|
referenced: v.referenced || false,
|
|
|
|
|
writable: v.writable || false,
|
|
|
|
|
referenced_from_script: v.referenced_from_script || false
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @param {{
|
|
|
|
@ -639,10 +624,8 @@ export default class Component {
|
|
|
|
|
}
|
|
|
|
|
if (node.declaration) {
|
|
|
|
|
if (node.declaration.type === 'VariableDeclaration') {
|
|
|
|
|
node.declaration.declarations.forEach(
|
|
|
|
|
/** @param {any} declarator */ (declarator) => {
|
|
|
|
|
extract_names(declarator.id).forEach(
|
|
|
|
|
/** @param {any} name */ (name) => {
|
|
|
|
|
node.declaration.declarations.forEach((declarator) => {
|
|
|
|
|
extract_names(declarator.id).forEach((name) => {
|
|
|
|
|
const variable = this.var_lookup.get(name);
|
|
|
|
|
variable.export_name = name;
|
|
|
|
|
if (
|
|
|
|
@ -654,21 +637,15 @@ export default class Component {
|
|
|
|
|
if (
|
|
|
|
|
!module_script &&
|
|
|
|
|
variable.writable &&
|
|
|
|
|
!(
|
|
|
|
|
variable.referenced ||
|
|
|
|
|
variable.referenced_from_script ||
|
|
|
|
|
variable.subscribable
|
|
|
|
|
)
|
|
|
|
|
!(variable.referenced || variable.referenced_from_script || variable.subscribable)
|
|
|
|
|
) {
|
|
|
|
|
this.warn(
|
|
|
|
|
/** @type {any} */ (declarator),
|
|
|
|
|
compiler_warnings.unused_export_let(this.name.name, name)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
const { name } = node.declaration.id;
|
|
|
|
|
const variable = this.var_lookup.get(name);
|
|
|
|
@ -676,8 +653,7 @@ export default class Component {
|
|
|
|
|
}
|
|
|
|
|
return node.declaration;
|
|
|
|
|
} else {
|
|
|
|
|
node.specifiers.forEach(
|
|
|
|
|
/** @param {any} specifier */ (specifier) => {
|
|
|
|
|
node.specifiers.forEach((specifier) => {
|
|
|
|
|
const variable = this.var_lookup.get(specifier.local.name);
|
|
|
|
|
if (variable) {
|
|
|
|
|
variable.export_name = specifier.exported.name;
|
|
|
|
@ -692,8 +668,7 @@ export default class Component {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -702,16 +677,14 @@ export default class Component {
|
|
|
|
|
/** @param {any} script */
|
|
|
|
|
extract_javascript(script) {
|
|
|
|
|
if (!script) return null;
|
|
|
|
|
return script.content.body.filter(
|
|
|
|
|
/** @param {any} node */ (node) => {
|
|
|
|
|
return script.content.body.filter((node) => {
|
|
|
|
|
if (!node) return false;
|
|
|
|
|
if (this.hoistable_nodes.has(node)) return false;
|
|
|
|
|
if (this.reactive_declaration_nodes.has(node)) return false;
|
|
|
|
|
if (node.type === 'ImportDeclaration') return false;
|
|
|
|
|
if (node.type === 'ExportDeclaration' && node.specifiers.length > 0) return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
walk_module_js() {
|
|
|
|
|
const component = this;
|
|
|
|
@ -730,11 +703,7 @@ export default class Component {
|
|
|
|
|
});
|
|
|
|
|
const { scope, globals } = create_scopes(script.content);
|
|
|
|
|
this.module_scope = scope;
|
|
|
|
|
scope.declarations.forEach(
|
|
|
|
|
/**
|
|
|
|
|
* @param {any} node
|
|
|
|
|
* @param {any} name
|
|
|
|
|
*/ (node, name) => {
|
|
|
|
|
scope.declarations.forEach((node, name) => {
|
|
|
|
|
if (name[0] === '$') {
|
|
|
|
|
return this.error(/** @type {any} */ (node), compiler_errors.illegal_declaration);
|
|
|
|
|
}
|
|
|
|
@ -748,13 +717,8 @@ export default class Component {
|
|
|
|
|
writable,
|
|
|
|
|
imported
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
globals.forEach(
|
|
|
|
|
/**
|
|
|
|
|
* @param {any} node
|
|
|
|
|
* @param {any} name
|
|
|
|
|
*/ (node, name) => {
|
|
|
|
|
});
|
|
|
|
|
globals.forEach((node, name) => {
|
|
|
|
|
if (name[0] === '$') {
|
|
|
|
|
return this.error(/** @type {any} */ (node), compiler_errors.illegal_subscription);
|
|
|
|
|
} else {
|
|
|
|
@ -764,8 +728,7 @@ export default class Component {
|
|
|
|
|
hoistable: true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
const { body } = script.content;
|
|
|
|
|
let i = body.length;
|
|
|
|
|
while (--i >= 0) {
|
|
|
|
@ -788,30 +751,22 @@ export default class Component {
|
|
|
|
|
const script = this.ast.instance;
|
|
|
|
|
if (!script) return;
|
|
|
|
|
// inject vars for reactive declarations
|
|
|
|
|
script.content.body.forEach(
|
|
|
|
|
/** @param {any} node */ (node) => {
|
|
|
|
|
script.content.body.forEach((node) => {
|
|
|
|
|
if (node.type !== 'LabeledStatement') return;
|
|
|
|
|
if (node.body.type !== 'ExpressionStatement') return;
|
|
|
|
|
const { expression } = node.body;
|
|
|
|
|
if (expression.type !== 'AssignmentExpression') return;
|
|
|
|
|
if (expression.left.type === 'MemberExpression') return;
|
|
|
|
|
extract_names(expression.left).forEach(
|
|
|
|
|
/** @param {any} name */ (name) => {
|
|
|
|
|
extract_names(expression.left).forEach((name) => {
|
|
|
|
|
if (!this.var_lookup.has(name) && name[0] !== '$') {
|
|
|
|
|
this.injected_reactive_declaration_vars.add(name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
const { scope: instance_scope, map, globals } = create_scopes(script.content);
|
|
|
|
|
this.instance_scope = instance_scope;
|
|
|
|
|
this.instance_scope_map = map;
|
|
|
|
|
instance_scope.declarations.forEach(
|
|
|
|
|
/**
|
|
|
|
|
* @param {any} node
|
|
|
|
|
* @param {any} name
|
|
|
|
|
*/ (node, name) => {
|
|
|
|
|
instance_scope.declarations.forEach((node, name) => {
|
|
|
|
|
if (name[0] === '$') {
|
|
|
|
|
return this.error(/** @type {any} */ (node), compiler_errors.illegal_declaration);
|
|
|
|
|
}
|
|
|
|
@ -825,17 +780,15 @@ export default class Component {
|
|
|
|
|
imported
|
|
|
|
|
});
|
|
|
|
|
this.node_for_declaration.set(name, node);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
// NOTE: add store variable first, then only $store value
|
|
|
|
|
// as `$store` will mark `store` variable as referenced and subscribable
|
|
|
|
|
const global_keys = Array.from(globals.keys());
|
|
|
|
|
const sorted_globals = [
|
|
|
|
|
...global_keys.filter(/** @param {any} key */ (key) => key[0] !== '$'),
|
|
|
|
|
...global_keys.filter(/** @param {any} key */ (key) => key[0] === '$')
|
|
|
|
|
...global_keys.filter((key) => key[0] !== '$'),
|
|
|
|
|
...global_keys.filter((key) => key[0] === '$')
|
|
|
|
|
];
|
|
|
|
|
sorted_globals.forEach(
|
|
|
|
|
/** @param {any} name */ (name) => {
|
|
|
|
|
sorted_globals.forEach((name) => {
|
|
|
|
|
if (this.var_lookup.has(name)) return;
|
|
|
|
|
const node = globals.get(name);
|
|
|
|
|
if (this.injected_reactive_declaration_vars.has(name)) {
|
|
|
|
@ -874,8 +827,7 @@ export default class Component {
|
|
|
|
|
hoistable: true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
this.track_references_and_mutations();
|
|
|
|
|
}
|
|
|
|
|
walk_instance_js_post_template() {
|
|
|
|
@ -909,12 +861,7 @@ export default class Component {
|
|
|
|
|
/** @type {import('estree').FunctionDeclaration | import('estree').FunctionExpression} */
|
|
|
|
|
let current_function = null;
|
|
|
|
|
walk(content, {
|
|
|
|
|
/**
|
|
|
|
|
* @param {import('estree').Node} node
|
|
|
|
|
* @param {import('estree').Node} parent
|
|
|
|
|
* @param {any} prop
|
|
|
|
|
* @param {any} index
|
|
|
|
|
*/
|
|
|
|
|
/** @type {import('estree-walker').SyncHandler} */
|
|
|
|
|
enter(node, parent, prop, index) {
|
|
|
|
|
if (node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') {
|
|
|
|
|
current_function_stack.push((current_function = node));
|
|
|
|
@ -953,8 +900,7 @@ export default class Component {
|
|
|
|
|
names.push(name);
|
|
|
|
|
}
|
|
|
|
|
if (names.length > 0) {
|
|
|
|
|
names.forEach(
|
|
|
|
|
/** @param {any} name */ (name) => {
|
|
|
|
|
names.forEach((name) => {
|
|
|
|
|
let current_scope = scope;
|
|
|
|
|
let declaration;
|
|
|
|
|
while (current_scope) {
|
|
|
|
@ -964,14 +910,17 @@ export default class Component {
|
|
|
|
|
}
|
|
|
|
|
current_scope = current_scope.parent;
|
|
|
|
|
}
|
|
|
|
|
if (declaration && /** @type {any} */ (declaration).kind === 'const' && !deep) {
|
|
|
|
|
if (
|
|
|
|
|
declaration &&
|
|
|
|
|
/** @type {import('estree').VariableDeclaration} */ (declaration).kind === 'const' &&
|
|
|
|
|
!deep
|
|
|
|
|
) {
|
|
|
|
|
component.error(/** @type {any} */ (node), {
|
|
|
|
|
code: 'assignment-to-const',
|
|
|
|
|
message: 'You are assigning to a const'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (node.type === 'ImportDeclaration') {
|
|
|
|
|
component.extract_imports(node);
|
|
|
|
@ -1054,8 +1003,7 @@ export default class Component {
|
|
|
|
|
const assignee = node.type === 'AssignmentExpression' ? node.left : node.argument;
|
|
|
|
|
const names = extract_names(/** @type {import('estree').Node} */ (assignee));
|
|
|
|
|
const deep = assignee.type === 'MemberExpression';
|
|
|
|
|
names.forEach(
|
|
|
|
|
/** @param {any} name */ (name) => {
|
|
|
|
|
names.forEach((name) => {
|
|
|
|
|
const scope_owner = scope.find_owner(name);
|
|
|
|
|
if (
|
|
|
|
|
scope_owner !== null
|
|
|
|
@ -1065,8 +1013,7 @@ export default class Component {
|
|
|
|
|
const variable = component.var_lookup.get(name);
|
|
|
|
|
variable[deep ? 'mutated' : 'reassigned'] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (is_used_as_reference(node, parent)) {
|
|
|
|
|
const object = get_object(node);
|
|
|
|
@ -1339,8 +1286,7 @@ export default class Component {
|
|
|
|
|
for (let i = 0; i < body.length; i += 1) {
|
|
|
|
|
const node = body[i];
|
|
|
|
|
if (node.type === 'VariableDeclaration') {
|
|
|
|
|
const all_hoistable = node.declarations.every(
|
|
|
|
|
/** @param {any} d */ (d) => {
|
|
|
|
|
const all_hoistable = node.declarations.every((d) => {
|
|
|
|
|
if (!d.init) return false;
|
|
|
|
|
if (d.init.type !== 'Literal') return false;
|
|
|
|
|
// everything except const values can be changed by e.g. svelte devtools
|
|
|
|
@ -1359,17 +1305,14 @@ export default class Component {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
if (all_hoistable) {
|
|
|
|
|
node.declarations.forEach(
|
|
|
|
|
/** @param {any} d */ (d) => {
|
|
|
|
|
node.declarations.forEach((d) => {
|
|
|
|
|
const variable = this.var_lookup.get(
|
|
|
|
|
/** @type {import('estree').Identifier} */ (d.id).name
|
|
|
|
|
);
|
|
|
|
|
variable.hoistable = true;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
hoistable_nodes.add(node);
|
|
|
|
|
body.splice(i--, 1);
|
|
|
|
|
this.fully_hoisted.push(node);
|
|
|
|
@ -1401,10 +1344,7 @@ export default class Component {
|
|
|
|
|
// handle cycles
|
|
|
|
|
walking.add(fn_declaration);
|
|
|
|
|
walk(fn_declaration, {
|
|
|
|
|
/**
|
|
|
|
|
* @param {import('estree').Node} node
|
|
|
|
|
* @param {any} parent
|
|
|
|
|
*/
|
|
|
|
|
/** @type {import('estree-walker').SyncHandler} */
|
|
|
|
|
enter(node, parent) {
|
|
|
|
|
if (!hoistable) return this.skip();
|
|
|
|
|
if (map.has(node)) {
|
|
|
|
@ -1488,8 +1428,7 @@ export default class Component {
|
|
|
|
|
* }>}
|
|
|
|
|
*/
|
|
|
|
|
const unsorted_reactive_declarations = [];
|
|
|
|
|
this.ast.instance.content.body.forEach(
|
|
|
|
|
/** @param {any} node */ (node) => {
|
|
|
|
|
this.ast.instance.content.body.forEach((node) => {
|
|
|
|
|
const ignores = extract_svelte_ignore_from_comments(node);
|
|
|
|
|
if (ignores.length) this.push_ignores(ignores);
|
|
|
|
|
if (node.type === 'LabeledStatement' && node.label.name === '$') {
|
|
|
|
@ -1502,10 +1441,7 @@ export default class Component {
|
|
|
|
|
const { declarations: outset_scope_decalarations } = this.instance_scope;
|
|
|
|
|
const map = this.instance_scope_map;
|
|
|
|
|
walk(node.body, {
|
|
|
|
|
/**
|
|
|
|
|
* @param {import('estree').Node} node
|
|
|
|
|
* @param {any} parent
|
|
|
|
|
*/
|
|
|
|
|
/** @type {import('estree-walker').SyncHandler} */
|
|
|
|
|
enter(node, parent) {
|
|
|
|
|
if (node.type === 'VariableDeclaration' && node.kind === 'var') {
|
|
|
|
|
const is_var_in_outset = node.declarations.some(
|
|
|
|
@ -1532,12 +1468,10 @@ export default class Component {
|
|
|
|
|
}
|
|
|
|
|
if (node.type === 'AssignmentExpression') {
|
|
|
|
|
const left = get_object(node.left);
|
|
|
|
|
extract_identifiers(left).forEach(
|
|
|
|
|
/** @param {any} node */ (node) => {
|
|
|
|
|
extract_identifiers(left).forEach((node) => {
|
|
|
|
|
assignee_nodes.add(node);
|
|
|
|
|
assignees.add(node.name);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
if (node.operator !== '=') {
|
|
|
|
|
dependencies.add(left.name);
|
|
|
|
|
}
|
|
|
|
@ -1563,8 +1497,7 @@ export default class Component {
|
|
|
|
|
module_dependencies.add(name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const is_writable_or_mutated =
|
|
|
|
|
variable && (variable.writable || variable.mutated);
|
|
|
|
|
const is_writable_or_mutated = variable && (variable.writable || variable.mutated);
|
|
|
|
|
if (
|
|
|
|
|
should_add_as_dependency &&
|
|
|
|
|
(!owner || owner === component.instance_scope) &&
|
|
|
|
@ -1603,44 +1536,29 @@ export default class Component {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (ignores.length) this.pop_ignores();
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
const lookup = new Map();
|
|
|
|
|
unsorted_reactive_declarations.forEach(
|
|
|
|
|
/** @param {any} declaration */ (declaration) => {
|
|
|
|
|
declaration.assignees.forEach(
|
|
|
|
|
/** @param {any} name */ (name) => {
|
|
|
|
|
unsorted_reactive_declarations.forEach((declaration) => {
|
|
|
|
|
declaration.assignees.forEach((name) => {
|
|
|
|
|
if (!lookup.has(name)) {
|
|
|
|
|
lookup.set(name, []);
|
|
|
|
|
}
|
|
|
|
|
// TODO warn or error if a name is assigned to in
|
|
|
|
|
// multiple reactive declarations?
|
|
|
|
|
lookup.get(name).push(declaration);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
const cycle = check_graph_for_cycles(
|
|
|
|
|
unsorted_reactive_declarations.reduce(
|
|
|
|
|
/**
|
|
|
|
|
* @param {any} acc
|
|
|
|
|
* @param {any} declaration
|
|
|
|
|
*/ (acc, declaration) => {
|
|
|
|
|
declaration.assignees.forEach(
|
|
|
|
|
/** @param {any} v */ (v) => {
|
|
|
|
|
declaration.dependencies.forEach(
|
|
|
|
|
/** @param {any} w */ (w) => {
|
|
|
|
|
unsorted_reactive_declarations.reduce((acc, declaration) => {
|
|
|
|
|
declaration.assignees.forEach((v) => {
|
|
|
|
|
declaration.dependencies.forEach((w) => {
|
|
|
|
|
if (!declaration.assignees.has(w)) {
|
|
|
|
|
acc.push([v, w]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
return acc;
|
|
|
|
|
},
|
|
|
|
|
[]
|
|
|
|
|
)
|
|
|
|
|
}, [])
|
|
|
|
|
);
|
|
|
|
|
if (cycle && cycle.length) {
|
|
|
|
|
const declarationList = lookup.get(cycle[0]);
|
|
|
|
@ -1651,15 +1569,13 @@ export default class Component {
|
|
|
|
|
/** @param {any} declaration */
|
|
|
|
|
const add_declaration = (declaration) => {
|
|
|
|
|
if (this.reactive_declarations.includes(declaration)) return;
|
|
|
|
|
declaration.dependencies.forEach(
|
|
|
|
|
/** @param {any} name */ (name) => {
|
|
|
|
|
declaration.dependencies.forEach((name) => {
|
|
|
|
|
if (declaration.assignees.has(name)) return;
|
|
|
|
|
const earlier_declarations = lookup.get(name);
|
|
|
|
|
if (earlier_declarations) {
|
|
|
|
|
earlier_declarations.forEach(add_declaration);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
this.reactive_declarations.push(declaration);
|
|
|
|
|
};
|
|
|
|
|
unsorted_reactive_declarations.forEach(add_declaration);
|
|
|
|
@ -1747,11 +1663,11 @@ function process_component_options(component, nodes) {
|
|
|
|
|
preserveWhitespace: !!component.compile_options.preserveWhitespace,
|
|
|
|
|
namespace: component.compile_options.namespace
|
|
|
|
|
};
|
|
|
|
|
const node = nodes.find(/** @param {any} node */ (node) => node.name === 'svelte:options');
|
|
|
|
|
const node = nodes.find((node) => node.name === 'svelte:options');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {any} attribute
|
|
|
|
|
* @param {any}params_0
|
|
|
|
|
* @param {any} params_0
|
|
|
|
|
*/
|
|
|
|
|
function get_value(attribute, { code, message }) {
|
|
|
|
|
const { value } = attribute;
|
|
|
|
@ -1767,8 +1683,7 @@ function process_component_options(component, nodes) {
|
|
|
|
|
return chunk.expression.value;
|
|
|
|
|
}
|
|
|
|
|
if (node) {
|
|
|
|
|
node.attributes.forEach(
|
|
|
|
|
/** @param {any} attribute */ (attribute) => {
|
|
|
|
|
node.attributes.forEach((attribute) => {
|
|
|
|
|
if (attribute.type === 'Attribute') {
|
|
|
|
|
const { name } = attribute;
|
|
|
|
|
|
|
|
|
@ -1809,18 +1724,13 @@ function process_component_options(component, nodes) {
|
|
|
|
|
} else if (value[0].expression.type !== 'ObjectExpression') {
|
|
|
|
|
return component.error(attribute, compiler_errors.invalid_customElement_attribute);
|
|
|
|
|
}
|
|
|
|
|
const tag = value[0].expression.properties.find(
|
|
|
|
|
/** @param {any} prop */ (prop) => prop.key.name === 'tag'
|
|
|
|
|
);
|
|
|
|
|
const tag = value[0].expression.properties.find((prop) => prop.key.name === 'tag');
|
|
|
|
|
if (tag) {
|
|
|
|
|
parse_tag(tag, tag.value?.value);
|
|
|
|
|
} else {
|
|
|
|
|
return component.error(attribute, compiler_errors.invalid_customElement_attribute);
|
|
|
|
|
}
|
|
|
|
|
const props = value[0].expression.properties.find(
|
|
|
|
|
/** @param {any} prop */
|
|
|
|
|
(prop) => prop.key.name === 'props'
|
|
|
|
|
);
|
|
|
|
|
const props = value[0].expression.properties.find((prop) => prop.key.name === 'props');
|
|
|
|
|
if (props) {
|
|
|
|
|
const error = () =>
|
|
|
|
|
component.error(attribute, compiler_errors.invalid_props_attribute);
|
|
|
|
@ -1828,9 +1738,8 @@ function process_component_options(component, nodes) {
|
|
|
|
|
return error();
|
|
|
|
|
}
|
|
|
|
|
component_options.customElement.props = {};
|
|
|
|
|
for (const property of /** @type {import('estree').ObjectExpression} */ (
|
|
|
|
|
props.value
|
|
|
|
|
).properties) {
|
|
|
|
|
for (const property of /** @type {import('estree').ObjectExpression} */ (props.value)
|
|
|
|
|
.properties) {
|
|
|
|
|
if (
|
|
|
|
|
property.type !== 'Property' ||
|
|
|
|
|
property.computed ||
|
|
|
|
@ -1866,7 +1775,6 @@ function process_component_options(component, nodes) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const shadow = value[0].expression.properties.find(
|
|
|
|
|
/** @param {any} prop */
|
|
|
|
|
(prop) => prop.key.name === 'shadow'
|
|
|
|
|
);
|
|
|
|
|
if (shadow) {
|
|
|
|
@ -1912,8 +1820,7 @@ function process_component_options(component, nodes) {
|
|
|
|
|
} else {
|
|
|
|
|
return component.error(attribute, compiler_errors.invalid_options_attribute);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return component_options;
|
|
|
|
|
}
|
|
|
|
|