Skip to content

Commit

Permalink
fix #4482
Browse files Browse the repository at this point in the history
  • Loading branch information
btakita committed Feb 28, 2020
1 parent 20e0790 commit 7bb2807
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea
.DS_Store
.nyc_output
yarn.lock
node_modules
*.map
/src/compiler/compile/internal_exports.ts
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

0 comments on commit 7bb2807

Please sign in to comment.