Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix https://github.com/sveltejs/svelte/issues/4482 #4483

Merged
merged 3 commits into from
Feb 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ cd svelte
npm install
```

> Do not use Yarn to install the dependencies, as the specific package versions in `package-lock.json` are used to build and test Svelte.

> Many tests depend on newlines being preserved as `<LF>`. On Windows, you can ensure this by cloning with:
> ```bash
> git -c core.autocrlf=false clone https://github.com/sveltejs/svelte.git
Expand Down
26 changes: 13 additions & 13 deletions src/compiler/compile/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export default class Component {
const program: any = { type: 'Program', body: result.js };

walk(program, {
enter: (node, parent, key) => {
enter: (node: Node, parent: Node, key) => {
if (node.type === 'Identifier') {
if (node.name[0] === '@') {
if (node.name[1] === '_') {
Expand Down Expand Up @@ -526,7 +526,7 @@ export default class Component {
if (!script) return;

walk(script.content, {
enter(node) {
enter(node: Node) {
if (node.type === 'LabeledStatement' && node.label.name === '$') {
component.warn(node as any, {
code: 'module-script-reactive-declaration',
Expand Down Expand Up @@ -715,7 +715,7 @@ export default class Component {
let scope_updated = false;

walk(content, {
enter(node, parent, prop, index) {
enter(node: Node, parent, prop, index) {
if (map.has(node)) {
scope = map.get(node);
}
Expand All @@ -741,7 +741,7 @@ export default class Component {
component.warn_on_undefined_store_value_references(node, parent, scope);
},

leave(node) {
leave(node: Node) {
// do it on leave, to prevent infinite loop
if (component.compile_options.dev && component.compile_options.loopGuardTimeout > 0) {
const to_replace_for_loop_protect = component.loop_protect(node, scope, component.compile_options.loopGuardTimeout);
Expand Down Expand Up @@ -785,7 +785,7 @@ export default class Component {
let scope = instance_scope;

walk(content, {
enter(node, parent) {
enter(node: Node, parent: Node) {
if (map.has(node)) {
scope = map.get(node);
}
Expand Down Expand Up @@ -813,7 +813,7 @@ export default class Component {
}
},

leave(node) {
leave(node: Node) {
if (map.has(node)) {
scope = scope.parent;
}
Expand Down Expand Up @@ -881,7 +881,7 @@ export default class Component {
let scope = instance_scope;

walk(this.ast.instance.content, {
enter(node, parent, key, index) {
enter(node: Node, parent, key, index) {
if (/Function/.test(node.type)) {
return this.skip();
}
Expand Down Expand Up @@ -958,7 +958,7 @@ export default class Component {
}
},

leave(node, parent, _key, index) {
leave(node: Node, parent, _key, index) {
if (map.has(node)) {
scope = scope.parent;
}
Expand Down Expand Up @@ -1059,7 +1059,7 @@ export default class Component {
walking.add(fn_declaration);

walk(fn_declaration, {
enter(node, parent) {
enter(node: Node, parent) {
if (!hoistable) return this.skip();

if (map.has(node)) {
Expand Down Expand Up @@ -1107,7 +1107,7 @@ export default class Component {
}
},

leave(node) {
leave(node: Node) {
if (map.has(node)) {
scope = scope.parent;
}
Expand Down Expand Up @@ -1150,7 +1150,7 @@ export default class Component {
const map = this.instance_scope_map;

walk(node.body, {
enter(node, parent) {
enter(node: Node, parent) {
if (map.has(node)) {
scope = map.get(node);
}
Expand Down Expand Up @@ -1190,7 +1190,7 @@ export default class Component {
}
},

leave(node) {
leave(node: Node) {
if (map.has(node)) {
scope = scope.parent;
}
Expand Down Expand Up @@ -1450,4 +1450,4 @@ function get_relative_path(from: string, to: string) {
}

return from_parts.concat(to_parts).join('/');
}
}
12 changes: 6 additions & 6 deletions src/compiler/compile/nodes/Let.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Node from './shared/Node';
import Component from '../Component';
import { walk } from 'estree-walker';
import { Identifier } from 'estree';
import { BasePattern, Identifier } from 'estree';

const applicable = new Set(['Identifier', 'ObjectExpression', 'ArrayExpression', 'Property']);

Expand All @@ -22,7 +22,7 @@ export default class Let extends Node {
this.value = info.expression;

walk(info.expression, {
enter(node) {
enter(node: Identifier|BasePattern) {
if (!applicable.has(node.type)) {
component.error(node as any, {
code: 'invalid-let',
Expand All @@ -31,21 +31,21 @@ export default class Let extends Node {
}

if (node.type === 'Identifier') {
names.push(node.name);
names.push((node as Identifier).name);
}

// slightly unfortunate hack
if (node.type === 'ArrayExpression') {
(node as any).type = 'ArrayPattern';
node.type = 'ArrayPattern';
}

if (node.type === 'ObjectExpression') {
(node as any).type = 'ObjectPattern';
node.type = 'ObjectPattern';
}
}
});
} else {
names.push(this.name.name);
}
}
}
}
4 changes: 2 additions & 2 deletions src/compiler/compile/nodes/shared/Expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export default class Expression {
}
},

leave(node) {
leave(node: Node) {
if (map.has(node)) {
scope = scope.parent;
}
Expand Down Expand Up @@ -338,7 +338,7 @@ export default class Expression {
});
}

return (this.manipulated = node);
return (this.manipulated = node as Node);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/compiler/compile/render_dom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export default function dom(
let execution_context: Node | null = null;

walk(component.ast.instance.content, {
enter(node) {
enter(node: Node) {
if (map.has(node)) {
scope = map.get(node) as Scope;

Expand All @@ -212,7 +212,7 @@ export default function dom(
}
},

leave(node) {
leave(node: Node) {
if (map.has(node)) {
scope = scope.parent;
}
Expand Down