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

[chore] update code-red, estree-walker, is-reference #6551

Merged
merged 3 commits into from
Jul 21, 2021
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
372 changes: 43 additions & 329 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,22 @@
"@rollup/plugin-sucrase": "^3.1.0",
"@rollup/plugin-typescript": "^2.0.1",
"@rollup/plugin-virtual": "^2.0.0",
"@sveltejs/eslint-config": "github:sveltejs/eslint-config#v5.6.0",
"@sveltejs/eslint-config": "github:sveltejs/eslint-config#v5.7.0",
"@types/mocha": "^7.0.0",
"@types/node": "^8.10.53",
"@typescript-eslint/eslint-plugin": "^4.9.0",
"@typescript-eslint/parser": "^4.9.0",
"acorn": "^8.4.1",
"agadoo": "^1.1.0",
"c8": "^5.0.1",
"code-red": "^0.2.1",
"code-red": "^0.2.2",
"codecov": "^3.5.0",
"css-tree": "^1.1.2",
"eslint": "^7.15.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-svelte3": "^2.7.3",
"estree-walker": "^1.0.0",
"is-reference": "^1.1.4",
"estree-walker": "^3.0.0",
"is-reference": "^3.0.0",
"jsdom": "^15.2.1",
"kleur": "^3.0.3",
"locate-character": "^2.0.5",
Expand Down
10 changes: 5 additions & 5 deletions src/compiler/compile/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import error from '../utils/error';
import get_code_frame from '../utils/get_code_frame';
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, { NodeWithPropertyDefinition } from 'is-reference';
import TemplateScope from './nodes/shared/TemplateScope';
import fuzzymatch from '../utils/fuzzymatch';
import get_object from './utils/get_object';
Expand Down Expand Up @@ -734,7 +734,7 @@ export default class Component {
let generator_count = 0;

walk(content, {
enter(node: Node, parent, prop, index) {
enter(node: Node, parent: Node, prop, index) {
if ((node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') && node.generator === true) {
generator_count++;
}
Expand Down Expand Up @@ -862,7 +862,7 @@ export default class Component {
this.warn(node as any, compiler_warnings.non_top_level_reactive_declaration);
}

if (is_reference(node, parent)) {
if (is_reference(node as NodeWithPropertyDefinition, parent as NodeWithPropertyDefinition)) {
const object = get_object(node);
const { name } = object;

Expand Down Expand Up @@ -1098,7 +1098,7 @@ export default class Component {
scope = map.get(node);
}

if (is_reference(node as Node, parent as Node)) {
if (is_reference(node as NodeWithPropertyDefinition, parent as NodeWithPropertyDefinition)) {
const { name } = flatten_reference(node);
const owner = scope.find_owner(name);

Expand Down Expand Up @@ -1220,7 +1220,7 @@ export default class Component {
} else if (node.type === 'UpdateExpression') {
const identifier = get_object(node.argument);
assignees.add(identifier.name);
} else if (is_reference(node as Node, parent as Node)) {
} else if (is_reference(node as NodeWithPropertyDefinition, parent as NodeWithPropertyDefinition)) {
const identifier = get_object(node);
if (!assignee_nodes.has(identifier)) {
const { name } = identifier;
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/compile/nodes/InlineComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default class InlineComponent extends Node {
});

const children = [];
for (let i=info.children.length - 1; i >= 0; i--) {
for (let i = info.children.length - 1; i >= 0; i--) {
const child = info.children[i];
if (child.type === 'SlotTemplate') {
children.push(child);
Expand All @@ -117,7 +117,7 @@ export default class InlineComponent extends Node {
};

// transfer attributes
for (let i=child.attributes.length - 1; i >= 0; i--) {
for (let i = child.attributes.length - 1; i >= 0; i--) {
const attribute = child.attributes[i];
if (attribute.type === 'Let') {
slot_template.attributes.push(attribute);
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/compile/nodes/shared/Context.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { x } from 'code-red';
import { Node, Identifier, Expression } from 'estree';
import { walk } from 'estree-walker';
import is_reference from 'is-reference';
import is_reference, { NodeWithPropertyDefinition } from 'is-reference';
import { clone } from '../../../utils/clone';

export interface Context {
Expand Down Expand Up @@ -85,7 +85,7 @@ function update_reference(contexts: Context[], n: number, expression: Expression
expression = clone(expression) as Expression;
walk(expression, {
enter(node, parent: Node) {
if (is_reference(node, parent)) {
if (is_reference(node as NodeWithPropertyDefinition, parent as NodeWithPropertyDefinition)) {
this.replace(find_from_context(node as Identifier));
this.skip();
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compile/render_dom/wrappers/EachBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ export default class EachBlockWrapper extends Wrapper {
this.else.fragment.render(this.else.block, null, x`#nodes` as Identifier);
}

this.context_props = this.node.contexts.map(prop => b`child_ctx[${renderer.context_lookup.get(prop.key.name).index}] = ${prop.default_modifier(prop.modifier(x`list[i]`), name => renderer.context_lookup.has(name) ? x`child_ctx[${renderer.context_lookup.get(name).index}]`: { type: 'Identifier', name })};`);
this.context_props = this.node.contexts.map(prop => b`child_ctx[${renderer.context_lookup.get(prop.key.name).index}] = ${prop.default_modifier(prop.modifier(x`list[i]`), name => renderer.context_lookup.has(name) ? x`child_ctx[${renderer.context_lookup.get(name).index}]` : { type: 'Identifier', name })};`);

if (this.node.has_binding) this.context_props.push(b`child_ctx[${renderer.context_lookup.get(this.vars.each_block_value.name).index}] = list;`);
if (this.node.has_binding || this.node.has_index_binding || this.node.index) this.context_props.push(b`child_ctx[${renderer.context_lookup.get(this.index_name.name).index}] = i;`);
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compile/render_ssr/handlers/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default function(node: Element, renderer: Renderer, options: RenderOption
const value = get_attribute_expression(value_attribute);
const type = node.get_static_attribute_value('type');
const bound = expression.node;
const condition = type === 'checkbox' ? x`~${bound}.indexOf(${value})`: x`${value} === ${bound}`;
const condition = type === 'checkbox' ? x`~${bound}.indexOf(${value})` : x`${value} === ${bound}`;
renderer.add_expression(x`${condition} ? @add_attribute("checked", true, 1) : ""`);
}
} else if (contenteditable && (name === 'textContent' || name === 'innerHTML')) {
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/compile/utils/is_used_as_reference.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Node } from 'estree';
import is_reference from 'is-reference';
import is_reference, { NodeWithPropertyDefinition } from 'is-reference';

export default function is_used_as_reference(
node: Node,
parent: Node
): boolean {
if (!is_reference(node, parent)) {
if (!is_reference(node as NodeWithPropertyDefinition, parent as NodeWithPropertyDefinition)) {
return false;
}
if (!parent) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/preprocess/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function parse_tag_attributes(str: string) {
.filter(Boolean)
.reduce((attrs, attr) => {
const i = attr.indexOf('=');
const [key, value] = i > 0 ? [attr.slice(0, i), attr.slice(i+1)] : [attr];
const [key, value] = i > 0 ? [attr.slice(0, i), attr.slice(i + 1)] : [attr];
const [, unquoted] = (value && value.match(/^['"](.*)['"]$/)) || [];

return { ...attrs, [key]: unquoted ?? value ?? true };
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/preprocess/replace_in_code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function calculate_replacements(
get_replacement(...match).then(
replacement => {
const matched_string = match[0];
const offset = match[match.length-2];
const offset = match[match.length - 2];

return ({ offset, length: matched_string.length, replacement });
}
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/utils/clone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export function clone(val) {
let k, out, tmp;

if (Array.isArray(val)) {
out = Array(k=val.length);
while (k--) out[k] = (tmp=val[k]) && typeof tmp === 'object' ? clone(tmp) : tmp;
out = Array(k = val.length);
while (k--) out[k] = (tmp = val[k]) && typeof tmp === 'object' ? clone(tmp) : tmp;
return out;
}

Expand All @@ -23,7 +23,7 @@ export function clone(val) {
writable: true
});
} else if (typeof val[k] !== 'function') { // MODIFICATION: skip functions
out[k] = (tmp=val[k]) && typeof tmp === 'object' ? clone(tmp) : tmp;
out[k] = (tmp = val[k]) && typeof tmp === 'object' ? clone(tmp) : tmp;
}
}
return out;
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/utils/mapped_code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ export function apply_preprocessor_sourcemap(filename: string, svelte_map: Sourc
export function parse_attached_sourcemap(processed: Processed, tag_name: 'script' | 'style'): void {
const r_in = '[#@]\\s*sourceMappingURL\\s*=\\s*(\\S*)';
const regex = (tag_name == 'script')
? new RegExp('(?://'+r_in+')|(?:/\\*'+r_in+'\\s*\\*/)$')
: new RegExp('/\\*'+r_in+'\\s*\\*/$');
? new RegExp('(?://' + r_in + ')|(?:/\\*' + r_in + '\\s*\\*/)$')
: new RegExp('/\\*' + r_in + '\\s*\\*/$');
function log_warning(message) {
// code_start: help to find preprocessor
const code_start = processed.code.length < 100 ? processed.code : (processed.code.slice(0, 100) + ' [...]');
Expand Down
2 changes: 1 addition & 1 deletion test/sourcemaps/samples/attached-sourcemap/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function get_processor(tag_name, search, replace) {

// change line + column
const indent = Array.from({ length: indent_size }).join(' ');
ms.prependLeft(idx, '\n'+indent);
ms.prependLeft(idx, '\n' + indent);

const map_opts = { source: filename, hires: true, includeContent: false };
const map = ms.generateMap(map_opts);
Expand Down