Skip to content

Commit

Permalink
chore: more specific typings, and add README note about Yarn (#4483)
Browse files Browse the repository at this point in the history
  • Loading branch information
btakita authored Feb 29, 2020
1 parent 3f647a8 commit 3a37de3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
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 @@ -818,7 +818,7 @@ export default class Component {
}
},

leave(node) {
leave(node: Node) {
if (map.has(node)) {
scope = scope.parent;
}
Expand Down Expand Up @@ -886,7 +886,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 @@ -963,7 +963,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 @@ -1064,7 +1064,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 @@ -1112,7 +1112,7 @@ export default class Component {
}
},

leave(node) {
leave(node: Node) {
if (map.has(node)) {
scope = scope.parent;
}
Expand Down Expand Up @@ -1155,7 +1155,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 @@ -1195,7 +1195,7 @@ export default class Component {
}
},

leave(node) {
leave(node: Node) {
if (map.has(node)) {
scope = scope.parent;
}
Expand Down Expand Up @@ -1455,4 +1455,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 3a37de3

Please sign in to comment.