Merge branch 'master' of github.com:sveltejs/svelte

pull/3818/head
Richard Harris 5 years ago
commit 33858a389b

@ -18,6 +18,7 @@ import { Ast, CompileOptions, Var, Warning } from '../interfaces';
import error from '../utils/error'; import error from '../utils/error';
import get_code_frame from '../utils/get_code_frame'; import get_code_frame from '../utils/get_code_frame';
import flatten_reference from './utils/flatten_reference'; import flatten_reference from './utils/flatten_reference';
import is_used_as_reference from './utils/is_used_as_reference';
import is_reference from 'is-reference'; import is_reference from 'is-reference';
import TemplateScope from './nodes/shared/TemplateScope'; import TemplateScope from './nodes/shared/TemplateScope';
import fuzzymatch from '../utils/fuzzymatch'; import fuzzymatch from '../utils/fuzzymatch';
@ -168,12 +169,13 @@ export default class Component {
this.tag = this.name.name; this.tag = this.name.name;
} }
this.walk_module_js(); this.walk_module_js_pre_template();
this.walk_instance_js_pre_template(); this.walk_instance_js_pre_template();
this.fragment = new Fragment(this, ast.html); this.fragment = new Fragment(this, ast.html);
this.name = this.get_unique_name(name); this.name = this.get_unique_name(name);
this.walk_module_js_post_template();
this.walk_instance_js_post_template(); this.walk_instance_js_post_template();
if (!compile_options.customElement) this.stylesheet.reify(); if (!compile_options.customElement) this.stylesheet.reify();
@ -346,6 +348,7 @@ export default class Component {
reassigned: v.reassigned || false, reassigned: v.reassigned || false,
referenced: v.referenced || false, referenced: v.referenced || false,
writable: v.writable || false, writable: v.writable || false,
referenced_from_script: v.referenced_from_script || false,
})), })),
stats: this.stats.render(), stats: this.stats.render(),
}; };
@ -447,22 +450,11 @@ export default class Component {
}); });
} }
extract_imports(content) { extract_imports(node) {
for (let i = 0; i < content.body.length; i += 1) {
const node = content.body[i];
if (node.type === 'ImportDeclaration') {
content.body.splice(i--, 1);
this.imports.push(node); this.imports.push(node);
} }
}
}
extract_exports(content) {
let i = content.body.length;
while (i--) {
const node = content.body[i];
extract_exports(node) {
if (node.type === 'ExportDefaultDeclaration') { if (node.type === 'ExportDefaultDeclaration') {
this.error(node, { this.error(node, {
code: `default-export`, code: `default-export`,
@ -483,6 +475,12 @@ export default class Component {
extract_names(declarator.id).forEach(name => { extract_names(declarator.id).forEach(name => {
const variable = this.var_lookup.get(name); const variable = this.var_lookup.get(name);
variable.export_name = name; variable.export_name = name;
if (variable.writable && !(variable.referenced || variable.referenced_from_script)) {
this.warn(declarator, {
code: `unused-export-let`,
message: `${this.name.name} has unused export property '${name}'. If it is for external reference only, please consider using \`export const '${name}'\``
});
}
}); });
}); });
} else { } else {
@ -492,18 +490,24 @@ export default class Component {
variable.export_name = name; variable.export_name = name;
} }
content.body[i] = node.declaration; return node.declaration;
} else { } else {
node.specifiers.forEach(specifier => { node.specifiers.forEach(specifier => {
const variable = this.var_lookup.get(specifier.local.name); const variable = this.var_lookup.get(specifier.local.name);
if (variable) { if (variable) {
variable.export_name = specifier.exported.name; variable.export_name = specifier.exported.name;
if (variable.writable && !(variable.referenced || variable.referenced_from_script)) {
this.warn(specifier, {
code: `unused-export-let`,
message: `${this.name.name} has unused export property '${specifier.exported.name}'. If it is for external reference only, please consider using \`export const '${specifier.exported.name}'\``
});
}
} }
}); });
content.body.splice(i, 1); return null;
}
} }
} }
} }
@ -522,7 +526,7 @@ export default class Component {
}); });
} }
walk_module_js() { walk_module_js_pre_template() {
const component = this; const component = this;
const script = this.ast.module; const script = this.ast.module;
if (!script) return; if (!script) return;
@ -573,9 +577,6 @@ export default class Component {
}); });
} }
}); });
this.extract_imports(script.content);
this.extract_exports(script.content);
} }
walk_instance_js_pre_template() { walk_instance_js_pre_template() {
@ -657,7 +658,10 @@ export default class Component {
this.add_reference(name.slice(1)); this.add_reference(name.slice(1));
const variable = this.var_lookup.get(name.slice(1)); const variable = this.var_lookup.get(name.slice(1));
if (variable) variable.subscribable = true; if (variable) {
variable.subscribable = true;
variable.referenced_from_script = true;
}
} else { } else {
this.add_var({ this.add_var({
name, name,
@ -667,29 +671,115 @@ export default class Component {
} }
}); });
this.extract_imports(script.content); this.track_references_and_mutations();
this.extract_exports(script.content); }
this.track_mutations();
walk_module_js_post_template() {
const script = this.ast.module;
if (!script) return;
const { body } = script.content;
let i = body.length;
while (--i >= 0) {
const node = body[i];
if (node.type === 'ImportDeclaration') {
this.extract_imports(node);
body.splice(i, 1);
}
if (/^Export/.test(node.type)) {
const replacement = this.extract_exports(node);
if (replacement) {
body[i] = replacement;
} else {
body.splice(i, 1);
}
}
}
} }
walk_instance_js_post_template() { walk_instance_js_post_template() {
const script = this.ast.instance; const script = this.ast.instance;
if (!script) return; if (!script) return;
this.warn_on_undefined_store_value_references(); this.post_template_walk();
this.hoist_instance_declarations(); this.hoist_instance_declarations();
this.extract_reactive_declarations(); this.extract_reactive_declarations();
} }
// TODO merge this with other walks that are independent post_template_walk() {
track_mutations() { const script = this.ast.instance;
if (!script) return;
const component = this; const component = this;
const { content } = script;
const { instance_scope, instance_scope_map: map } = this; const { instance_scope, instance_scope_map: map } = this;
let scope = instance_scope; let scope = instance_scope;
walk(this.ast.instance.content, { const toRemove = [];
enter(node) { const remove = (parent, prop, index) => {
toRemove.unshift([parent, prop, index]);
};
walk(content, {
enter(node, parent, prop, index) {
if (map.has(node)) {
scope = map.get(node);
}
if (node.type === 'ImportDeclaration') {
component.extract_imports(node);
// TODO: to use actual remove
remove(parent, prop, index);
return this.skip();
}
if (/^Export/.test(node.type)) {
const replacement = component.extract_exports(node);
if (replacement) {
this.replace(replacement);
} else {
// TODO: to use actual remove
remove(parent, prop, index);
}
return this.skip();
}
component.warn_on_undefined_store_value_references(node, parent, scope);
},
leave(node) {
if (map.has(node)) {
scope = scope.parent;
}
},
});
for (const [parent, prop, index] of toRemove) {
if (parent) {
if (index !== null) {
parent[prop].splice(index, 1);
} else {
delete parent[prop];
}
}
}
}
track_references_and_mutations() {
const script = this.ast.instance;
if (!script) return;
const component = this;
const { content } = script;
const { instance_scope, instance_scope_map: map } = this;
let scope = instance_scope;
walk(content, {
enter(node, parent) {
if (map.has(node)) { if (map.has(node)) {
scope = map.get(node); scope = map.get(node);
} }
@ -707,6 +797,14 @@ export default class Component {
} }
}); });
} }
if (is_used_as_reference(node, parent)) {
const object = get_object(node);
if (scope.find_owner(object.name) === instance_scope) {
const variable = component.var_lookup.get(object.name);
variable.referenced_from_script = true;
}
}
}, },
leave(node) { leave(node) {
@ -717,24 +815,13 @@ export default class Component {
}); });
} }
warn_on_undefined_store_value_references() { warn_on_undefined_store_value_references(node, parent, scope) {
// TODO this pattern happens a lot... can we abstract it
// (or better still, do fewer AST walks)?
const component = this;
let { instance_scope: scope, instance_scope_map: map } = this;
walk(this.ast.instance.content, {
enter(node, parent) {
if (map.has(node)) {
scope = map.get(node);
}
if ( if (
node.type === 'LabeledStatement' && node.type === 'LabeledStatement' &&
node.label.name === '$' && node.label.name === '$' &&
parent.type !== 'Program' parent.type !== 'Program'
) { ) {
component.warn(node as any, { this.warn(node as any, {
code: 'non-top-level-reactive-declaration', code: 'non-top-level-reactive-declaration',
message: '$: has no effect outside of the top-level', message: '$: has no effect outside of the top-level',
}); });
@ -745,17 +832,9 @@ export default class Component {
const { name } = object; const { name } = object;
if (name[0] === '$' && !scope.has(name)) { if (name[0] === '$' && !scope.has(name)) {
component.warn_if_undefined(name, object, null); this.warn_if_undefined(name, object, null);
}
} }
},
leave(node) {
if (map.has(node)) {
scope = scope.parent;
} }
},
});
} }
invalidate(name, value?) { invalidate(name, value?) {

@ -6,6 +6,7 @@ import { is_void, sanitize } from '../../../../utils/names';
import FragmentWrapper from '../Fragment'; import FragmentWrapper from '../Fragment';
import { escape_html, string_literal } from '../../../utils/stringify'; import { escape_html, string_literal } from '../../../utils/stringify';
import TextWrapper from '../Text'; import TextWrapper from '../Text';
import TagWrapper from '../shared/Tag';
import fix_attribute_casing from './fix_attribute_casing'; import fix_attribute_casing from './fix_attribute_casing';
import { b, x, p } from 'code-red'; import { b, x, p } from 'code-red';
import { namespaces } from '../../../../utils/namespaces'; import { namespaces } from '../../../../utils/namespaces';
@ -849,7 +850,7 @@ export default class ElementWrapper extends Wrapper {
} }
} }
function to_html(wrappers: Array<ElementWrapper | TextWrapper>, block: Block, literal: any, state: any) { function to_html(wrappers: Array<ElementWrapper | TextWrapper | TagWrapper>, block: Block, literal: any, state: any) {
wrappers.forEach(wrapper => { wrappers.forEach(wrapper => {
if (wrapper.node.type === 'Text') { if (wrapper.node.type === 'Text') {
if ((wrapper as TextWrapper).use_space()) state.quasi.value.raw += ' '; if ((wrapper as TextWrapper).use_space()) state.quasi.value.raw += ' ';
@ -867,6 +868,15 @@ function to_html(wrappers: Array<ElementWrapper | TextWrapper>, block: Block, li
.replace(/\$/g, '\\$'); .replace(/\$/g, '\\$');
} }
else if (wrapper.node.type === 'MustacheTag' || wrapper.node.type === 'RawMustacheTag' ) {
literal.quasis.push(state.quasi);
literal.expressions.push(wrapper.node.expression.manipulate(block));
state.quasi = {
type: 'TemplateElement',
value: { raw: '' }
};
}
else if (wrapper.node.name === 'noscript') { else if (wrapper.node.name === 'noscript') {
// do nothing // do nothing
} }

@ -12,7 +12,6 @@ export default class MustacheTagWrapper extends Tag {
constructor(renderer: Renderer, block: Block, parent: Wrapper, node: MustacheTag | RawMustacheTag) { constructor(renderer: Renderer, block: Block, parent: Wrapper, node: MustacheTag | RawMustacheTag) {
super(renderer, block, parent, node); super(renderer, block, parent, node);
this.cannot_use_innerhtml();
} }
render(block: Block, parent_node: Identifier, parent_nodes: Identifier) { render(block: Block, parent_node: Identifier, parent_nodes: Identifier) {

@ -11,11 +11,17 @@ export default class Tag extends Wrapper {
constructor(renderer: Renderer, block: Block, parent: Wrapper, node: MustacheTag | RawMustacheTag) { constructor(renderer: Renderer, block: Block, parent: Wrapper, node: MustacheTag | RawMustacheTag) {
super(renderer, block, parent, node); super(renderer, block, parent, node);
if (!this.is_dependencies_static()) {
this.cannot_use_innerhtml(); this.cannot_use_innerhtml();
}
block.add_dependencies(node.expression.dependencies); block.add_dependencies(node.expression.dependencies);
} }
is_dependencies_static() {
return this.node.expression.contextual_dependencies.size === 0 && this.node.expression.dynamic_dependencies().length === 0;
}
rename_this_method( rename_this_method(
block: Block, block: Block,
update: ((value: Node) => (Node | Node[])) update: ((value: Node) => (Node | Node[]))

@ -0,0 +1,34 @@
import { Node } from 'estree';
import is_reference from 'is-reference';
export default function is_used_as_reference(
node: Node,
parent: Node
): boolean {
if (!is_reference(node, parent)) {
return false;
}
if (!parent) {
return true;
}
/* eslint-disable no-fallthrough */
switch (parent.type) {
// disregard the `foo` in `const foo = bar`
case 'VariableDeclarator':
return node !== parent.id;
// disregard the `foo`, `bar` in `function foo(bar){}`
case 'FunctionDeclaration':
// disregard the `foo` in `import { foo } from 'foo'`
case 'ImportSpecifier':
// disregard the `foo` in `import foo from 'foo'`
case 'ImportDefaultSpecifier':
// disregard the `foo` in `import * as foo from 'foo'`
case 'ImportNamespaceSpecifier':
// disregard the `foo` in `export { foo }`
case 'ExportSpecifier':
return false;
default:
return true;
}
}

@ -148,7 +148,8 @@ export interface Var {
module?: boolean; module?: boolean;
mutated?: boolean; mutated?: boolean;
reassigned?: boolean; reassigned?: boolean;
referenced?: boolean; referenced?: boolean; // referenced from template scope
referenced_from_script?: boolean; // referenced from script
writable?: boolean; writable?: boolean;
// used internally, but not exposed // used internally, but not exposed

@ -1,28 +1,23 @@
import { import {
SvelteComponent, SvelteComponent,
append,
detach, detach,
element, element,
init, init,
insert, insert,
noop, noop,
safe_not_equal, safe_not_equal
text
} from "svelte/internal"; } from "svelte/internal";
function create_fragment(ctx) { function create_fragment(ctx) {
let b; let b;
let t_value = get_answer() + "";
let t;
return { return {
c() { c() {
b = element("b"); b = element("b");
t = text(t_value); b.innerHTML = `${get_answer()}`;
}, },
m(target, anchor) { m(target, anchor) {
insert(target, b, anchor); insert(target, b, anchor);
append(b, t);
}, },
p: noop, p: noop,
i: noop, i: noop,

@ -1,28 +1,23 @@
import { import {
SvelteComponent, SvelteComponent,
append,
detach, detach,
element, element,
init, init,
insert, insert,
noop, noop,
safe_not_equal, safe_not_equal
text
} from "svelte/internal"; } from "svelte/internal";
function create_fragment(ctx) { function create_fragment(ctx) {
let b; let b;
let t_value = get_answer() + "";
let t;
return { return {
c() { c() {
b = element("b"); b = element("b");
t = text(t_value); b.innerHTML = `${get_answer()}`;
}, },
m(target, anchor) { m(target, anchor) {
insert(target, b, anchor); insert(target, b, anchor);
append(b, t);
}, },
p: noop, p: noop,
i: noop, i: noop,

@ -1,33 +1,23 @@
import { import {
SvelteComponent, SvelteComponent,
append,
detach, detach,
element, element,
init, init,
insert, insert,
noop, noop,
safe_not_equal, safe_not_equal
text
} from "svelte/internal"; } from "svelte/internal";
function create_fragment(ctx) { function create_fragment(ctx) {
let h1; let h1;
let t0;
let t1;
let t2;
return { return {
c() { c() {
h1 = element("h1"); h1 = element("h1");
t0 = text("Hello "); h1.innerHTML = `Hello ${name}!`;
t1 = text(name);
t2 = text("!");
}, },
m(target, anchor) { m(target, anchor) {
insert(target, h1, anchor); insert(target, h1, anchor);
append(h1, t0);
append(h1, t1);
append(h1, t2);
}, },
p: noop, p: noop,
i: noop, i: noop,

@ -0,0 +1,78 @@
import {
SvelteComponent,
append,
detach,
element,
init,
insert,
noop,
safe_not_equal,
set_data,
space,
text
} from "svelte/internal";
function create_fragment(ctx) {
let div0;
let t7;
let div1;
let p3;
let t8;
let t9;
return {
c() {
div0 = element("div");
div0.innerHTML = `<p>Hello world</p>
<p>Hello ${world1}</p>
<p>Hello ${world2}</p>`;
t7 = space();
div1 = element("div");
p3 = element("p");
t8 = text("Hello ");
t9 = text(ctx.world3);
},
m(target, anchor) {
insert(target, div0, anchor);
insert(target, t7, anchor);
insert(target, div1, anchor);
append(div1, p3);
append(p3, t8);
append(p3, t9);
},
p(changed, ctx) {
if (changed.world3) set_data(t9, ctx.world3);
},
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(div0);
if (detaching) detach(t7);
if (detaching) detach(div1);
}
};
}
let world1 = "world";
let world2 = "world";
function instance($$self, $$props, $$invalidate) {
const world3 = "world";
function foo() {
$$invalidate("world3", world3 = "svelte");
}
return { world3 };
}
class Component extends SvelteComponent {
constructor(options) {
super();
init(this, options, instance, create_fragment, safe_not_equal, []);
}
}
export default Component;

@ -0,0 +1,17 @@
<script>
let world1 = 'world';
let world2 = 'world';
const world3 = 'world';
function foo() {
world3 = 'svelte';
}
</script>
<div>
<p>Hello world</p>
<p>Hello {world1}</p>
<p>Hello {world2}</p>
</div>
<div>
<p>Hello {world3}</p>
</div>

@ -166,7 +166,8 @@ describe("runtime", () => {
mod, mod,
target, target,
window, window,
raf raf,
compileOptions
})).then(() => { })).then(() => {
component.$destroy(); component.$destroy();

@ -3,7 +3,8 @@ import order from './order.js';
export default { export default {
skip_if_ssr: true, skip_if_ssr: true,
test({ assert, component, target }) { test({ assert, component, target, compileOptions }) {
if (compileOptions.hydratable) {
assert.deepEqual(order, [ assert.deepEqual(order, [
'0: beforeUpdate', '0: beforeUpdate',
'0: render', '0: render',
@ -20,9 +21,29 @@ export default {
'3: onMount', '3: onMount',
'3: afterUpdate', '3: afterUpdate',
'0: onMount', '0: onMount',
'0: afterUpdate' '0: afterUpdate',
]); ]);
} else {
assert.deepEqual(order, [
'0: beforeUpdate',
'0: render',
'1: beforeUpdate',
'2: beforeUpdate',
'3: beforeUpdate',
'1: render',
'2: render',
'3: render',
'1: onMount',
'1: afterUpdate',
'2: onMount',
'2: afterUpdate',
'3: onMount',
'3: afterUpdate',
'0: onMount',
'0: afterUpdate',
]);
}
order.length = 0; order.length = 0;
} },
}; };

@ -0,0 +1,21 @@
<script>
var a = 1;
let b = 1;
const c = 1;
var d = 1;
let e = 1;
const f = 1;
export { d, e, f};
export var g = 1;
export let h = 1;
export const i = 1;
export let j = () => {};
export const k = () => {};
export function l() {};
var m = 1;
let n = 1;
const o = 1;
function foo() {
return m + n + o;
}
</script>

@ -0,0 +1,77 @@
[
{
"code": "unused-export-let",
"end": {
"character": 103,
"column": 12,
"line": 8
},
"message": "Component has unused export property 'd'. If it is for external reference only, please consider using `export const 'd'`",
"pos": 102,
"start": {
"character": 102,
"column": 11,
"line": 8
}
},
{
"code": "unused-export-let",
"end": {
"character": 106,
"column": 15,
"line": 8
},
"message": "Component has unused export property 'e'. If it is for external reference only, please consider using `export const 'e'`",
"pos": 105,
"start": {
"character": 105,
"column": 14,
"line": 8
}
},
{
"code": "unused-export-let",
"end": {
"character": 130,
"column": 18,
"line": 9
},
"message": "Component has unused export property 'g'. If it is for external reference only, please consider using `export const 'g'`",
"pos": 125,
"start": {
"character": 125,
"column": 13,
"line": 9
}
},
{
"code": "unused-export-let",
"end": {
"character": 150,
"column": 18,
"line": 10
},
"message": "Component has unused export property 'h'. If it is for external reference only, please consider using `export const 'h'`",
"pos": 145,
"start": {
"character": 145,
"column": 13,
"line": 10
}
},
{
"code": "unused-export-let",
"end": {
"character": 199,
"column": 25,
"line": 12
},
"message": "Component has unused export property 'j'. If it is for external reference only, please consider using `export const 'j'`",
"pos": 187,
"start": {
"character": 187,
"column": 13,
"line": 12
}
}
]

@ -9,6 +9,7 @@ export default {
mutated: false, mutated: false,
reassigned: false, reassigned: false,
referenced: true, referenced: true,
referenced_from_script: false,
writable: false writable: false
} }
]); ]);

@ -9,6 +9,7 @@ export default {
mutated: false, mutated: false,
reassigned: false, reassigned: false,
referenced: true, referenced: true,
referenced_from_script: false,
writable: false writable: false
} }
]); ]);

@ -9,6 +9,7 @@ export default {
name: 'hoistable_foo', name: 'hoistable_foo',
reassigned: false, reassigned: false,
referenced: true, referenced: true,
referenced_from_script: false,
writable: false writable: false
}, },
{ {
@ -19,6 +20,7 @@ export default {
name: 'foo', name: 'foo',
reassigned: false, reassigned: false,
referenced: true, referenced: true,
referenced_from_script: false,
writable: true writable: true
} }
]); ]);

@ -9,6 +9,7 @@ export default {
name: 'hoistable_foo', name: 'hoistable_foo',
reassigned: false, reassigned: false,
referenced: true, referenced: true,
referenced_from_script: false,
writable: false writable: false
}, },
{ {
@ -19,6 +20,7 @@ export default {
name: 'foo', name: 'foo',
reassigned: false, reassigned: false,
referenced: true, referenced: true,
referenced_from_script: false,
writable: true writable: true
} }
]); ]);

@ -9,6 +9,7 @@ export default {
mutated: false, mutated: false,
reassigned: false, reassigned: false,
referenced: true, referenced: true,
referenced_from_script: false,
writable: false writable: false
} }
]); ]);

@ -9,6 +9,7 @@ export default {
mutated: false, mutated: false,
reassigned: false, reassigned: false,
referenced: true, referenced: true,
referenced_from_script: false,
writable: true writable: true
} }
]); ]);

@ -9,6 +9,7 @@ export default {
mutated: false, mutated: false,
reassigned: false, reassigned: false,
referenced: false, referenced: false,
referenced_from_script: false,
writable: true writable: true
}, },
{ {
@ -19,6 +20,7 @@ export default {
mutated: false, mutated: false,
reassigned: false, reassigned: false,
referenced: true, referenced: true,
referenced_from_script: false,
writable: true writable: true
} }
]); ]);

@ -9,6 +9,7 @@ export default {
mutated: false, mutated: false,
reassigned: false, reassigned: false,
referenced: true, referenced: true,
referenced_from_script: true,
writable: true writable: true
}, },
{ {
@ -19,6 +20,7 @@ export default {
mutated: false, mutated: false,
reassigned: true, reassigned: true,
referenced: true, referenced: true,
referenced_from_script: false,
writable: true writable: true
} }
]); ]);

@ -9,6 +9,7 @@ export default {
mutated: false, mutated: false,
reassigned: false, reassigned: false,
referenced: false, referenced: false,
referenced_from_script: false,
writable: false writable: false
}, },
{ {
@ -19,6 +20,7 @@ export default {
mutated: false, mutated: false,
reassigned: false, reassigned: false,
referenced: false, referenced: false,
referenced_from_script: false,
writable: false writable: false
}, },
{ {
@ -29,6 +31,7 @@ export default {
mutated: false, mutated: false,
reassigned: false, reassigned: false,
referenced: false, referenced: false,
referenced_from_script: false,
writable: false writable: false
} }
]); ]);

@ -9,6 +9,7 @@ export default {
mutated: false, mutated: false,
reassigned: true, reassigned: true,
referenced: true, referenced: true,
referenced_from_script: false,
writable: true writable: true
}, },
{ {
@ -19,6 +20,7 @@ export default {
mutated: true, mutated: true,
reassigned: false, reassigned: false,
referenced: true, referenced: true,
referenced_from_script: false,
writable: false writable: false
} }
]); ]);

@ -9,6 +9,7 @@ export default {
mutated: false, mutated: false,
reassigned: true, reassigned: true,
referenced: true, referenced: true,
referenced_from_script: false,
writable: true writable: true
}, },
{ {
@ -19,6 +20,7 @@ export default {
mutated: true, mutated: true,
reassigned: false, reassigned: false,
referenced: true, referenced: true,
referenced_from_script: false,
writable: false writable: false
} }
]); ]);

@ -9,6 +9,7 @@ export default {
mutated: false, mutated: false,
reassigned: false, reassigned: false,
referenced: true, referenced: true,
referenced_from_script: false,
writable: true writable: true
}, },
{ {
@ -19,6 +20,7 @@ export default {
mutated: false, mutated: false,
reassigned: false, reassigned: false,
referenced: true, referenced: true,
referenced_from_script: false,
writable: true writable: true
}, },
{ {
@ -29,6 +31,7 @@ export default {
mutated: false, mutated: false,
reassigned: false, reassigned: false,
referenced: false, referenced: false,
referenced_from_script: true,
writable: true writable: true
}, },
{ {
@ -39,6 +42,7 @@ export default {
mutated: false, mutated: false,
reassigned: true, reassigned: true,
referenced: true, referenced: true,
referenced_from_script: true,
writable: true writable: true
} }
]); ]);

@ -0,0 +1,160 @@
export default {
test(assert, vars) {
assert.deepEqual(vars, [
{
name: 'i',
export_name: null,
injected: false,
module: false,
mutated: false,
reassigned: false,
referenced: false,
writable: false,
referenced_from_script: false,
},
{
name: 'j',
export_name: null,
injected: false,
module: false,
mutated: false,
reassigned: false,
referenced: false,
writable: false,
referenced_from_script: false,
},
{
name: 'k',
export_name: null,
injected: false,
module: false,
mutated: false,
reassigned: false,
referenced: false,
writable: false,
referenced_from_script: false,
},
{
name: 'a',
export_name: null,
injected: false,
module: false,
mutated: false,
reassigned: true,
referenced: false,
writable: true,
referenced_from_script: true,
},
{
name: 'b',
export_name: null,
injected: false,
module: false,
mutated: false,
reassigned: false,
referenced: false,
writable: true,
referenced_from_script: true,
},
{
name: 'c',
export_name: null,
injected: false,
module: false,
mutated: false,
reassigned: false,
referenced: false,
writable: true,
referenced_from_script: true,
},
{
name: 'd',
export_name: null,
injected: false,
module: false,
mutated: false,
reassigned: false,
referenced: false,
writable: true,
referenced_from_script: true,
},
{
name: 'e',
export_name: null,
injected: false,
module: false,
mutated: false,
reassigned: false,
referenced: false,
writable: true,
referenced_from_script: false,
},
{
name: 'f',
export_name: 'f',
injected: false,
module: false,
mutated: false,
reassigned: false,
referenced: false,
writable: true,
referenced_from_script: false,
},
{
name: 'g',
export_name: null,
injected: false,
module: false,
mutated: false,
reassigned: false,
referenced: false,
writable: true,
referenced_from_script: true,
},
{
name: 'h',
export_name: null,
injected: false,
module: false,
mutated: false,
reassigned: true,
referenced: false,
writable: true,
referenced_from_script: true,
},
{
name: 'foo',
export_name: null,
injected: false,
module: false,
mutated: false,
reassigned: false,
referenced: false,
writable: false,
referenced_from_script: false,
},
{
name: 'l',
export_name: null,
injected: false,
module: false,
mutated: false,
reassigned: false,
referenced: false,
referenced_from_script: true,
writable: false,
},
{
name: 'bar',
export_name: 'bar',
injected: false,
module: false,
mutated: false,
reassigned: false,
referenced: false,
writable: false,
referenced_from_script: false,
},
]);
},
};

@ -0,0 +1,16 @@
<script>
import i from 'foo';
import * as j from 'foo';
import { k } from 'foo';
let a, b, c, d, e, f, g, h;
function foo() {
a = 1;
console.log(b);
return c + d.e + h++ + l();
}
function l() {}
export { f }
export const bar = g;
</script>

@ -9,6 +9,7 @@ export default {
mutated: false, mutated: false,
reassigned: false, reassigned: false,
referenced: true, referenced: true,
referenced_from_script: false,
writable: true writable: true
}, },
{ {
@ -19,6 +20,7 @@ export default {
mutated: true, mutated: true,
reassigned: false, reassigned: false,
referenced: true, referenced: true,
referenced_from_script: false,
writable: true writable: true
} }
]); ]);

@ -9,6 +9,7 @@ export default {
mutated: false, mutated: false,
reassigned: false, reassigned: false,
referenced: true, referenced: true,
referenced_from_script: true,
writable: true writable: true
}, },
{ {
@ -19,6 +20,7 @@ export default {
mutated: true, mutated: true,
reassigned: false, reassigned: false,
referenced: false, referenced: false,
referenced_from_script: false,
writable: true writable: true
} }
]); ]);

@ -9,6 +9,7 @@ export default {
name: 'Bar', name: 'Bar',
reassigned: false, reassigned: false,
referenced: true, referenced: true,
referenced_from_script: false,
writable: false, writable: false,
}, },
{ {
@ -19,6 +20,7 @@ export default {
name: 'foo', name: 'foo',
reassigned: false, reassigned: false,
referenced: true, referenced: true,
referenced_from_script: false,
writable: true, writable: true,
}, },
{ {
@ -29,6 +31,7 @@ export default {
name: 'baz', name: 'baz',
reassigned: false, reassigned: false,
referenced: true, referenced: true,
referenced_from_script: false,
writable: true, writable: true,
}, },
]); ]);

@ -9,6 +9,7 @@ export default {
name: 'hoistable_foo', name: 'hoistable_foo',
reassigned: false, reassigned: false,
referenced: true, referenced: true,
referenced_from_script: false,
writable: false writable: false
}, },
{ {
@ -19,6 +20,7 @@ export default {
name: 'hoistable_bar', name: 'hoistable_bar',
reassigned: false, reassigned: false,
referenced: true, referenced: true,
referenced_from_script: false,
writable: false writable: false
}, },
{ {
@ -29,6 +31,7 @@ export default {
name: 'hoistable_baz', name: 'hoistable_baz',
reassigned: false, reassigned: false,
referenced: true, referenced: true,
referenced_from_script: false,
writable: false writable: false
}, },
{ {
@ -39,6 +42,7 @@ export default {
name: 'foo', name: 'foo',
reassigned: false, reassigned: false,
referenced: true, referenced: true,
referenced_from_script: false,
writable: true writable: true
}, },
{ {
@ -49,6 +53,7 @@ export default {
name: 'bar', name: 'bar',
reassigned: false, reassigned: false,
referenced: true, referenced: true,
referenced_from_script: false,
writable: true writable: true
}, },
{ {
@ -59,6 +64,7 @@ export default {
name: 'baz', name: 'baz',
reassigned: false, reassigned: false,
referenced: true, referenced: true,
referenced_from_script: false,
writable: true writable: true
} }
]); ]);

Loading…
Cancel
Save