From dfee58656771f8a46ac52b1429fee34ccbe1946d Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Thu, 11 May 2023 18:12:36 +0200 Subject: [PATCH] bunch uf utils --- .../utils/{__test__.ts => __test__.js} | 34 +++++++++---------- src/compiler/compile/utils/add_to_set.js | 11 ++++++ src/compiler/compile/utils/add_to_set.ts | 6 ---- .../compile/utils/check_enable_sourcemap.js | 7 ++++ .../compile/utils/check_enable_sourcemap.ts | 8 ----- ...or_cycles.ts => check_graph_for_cycles.js} | 9 +++-- ...iteral.ts => collapse_template_literal.js} | 6 ++-- src/compiler/compile/utils/compare_node.js | 21 ++++++++++++ src/compiler/compile/utils/compare_node.ts | 19 ----------- ...{contenteditable.ts => contenteditable.js} | 16 ++++----- ...tten_reference.ts => flatten_reference.js} | 14 +++++--- ..._filename.ts => get_name_from_filename.js} | 5 ++- src/compiler/compile/utils/get_object.js | 7 ++++ src/compiler/compile/utils/get_object.ts | 6 ---- .../compile/utils/{hash.ts => hash.js} | 6 +++- ...s_reference.ts => is_used_as_reference.js} | 18 +++++++--- src/compiler/compile/utils/replace_object.js | 16 +++++++++ src/compiler/compile/utils/replace_object.ts | 14 -------- ...erved_keywords.ts => reserved_keywords.js} | 1 + .../compile/utils/{scope.ts => scope.js} | 6 ++-- .../utils/string_to_member_expression.js | 19 +++++++++++ .../utils/string_to_member_expression.ts | 17 ---------- .../utils/{stringify.ts => stringify.js} | 16 ++++++--- 23 files changed, 164 insertions(+), 118 deletions(-) rename src/compiler/compile/utils/{__test__.ts => __test__.js} (68%) create mode 100644 src/compiler/compile/utils/add_to_set.js delete mode 100644 src/compiler/compile/utils/add_to_set.ts create mode 100644 src/compiler/compile/utils/check_enable_sourcemap.js delete mode 100644 src/compiler/compile/utils/check_enable_sourcemap.ts rename src/compiler/compile/utils/{check_graph_for_cycles.ts => check_graph_for_cycles.js} (73%) rename src/compiler/compile/utils/{collapse_template_literal.ts => collapse_template_literal.js} (84%) create mode 100644 src/compiler/compile/utils/compare_node.js delete mode 100644 src/compiler/compile/utils/compare_node.ts rename src/compiler/compile/utils/{contenteditable.ts => contenteditable.js} (72%) rename src/compiler/compile/utils/{flatten_reference.ts => flatten_reference.js} (70%) rename src/compiler/compile/utils/{get_name_from_filename.ts => get_name_from_filename.js} (91%) create mode 100644 src/compiler/compile/utils/get_object.js delete mode 100644 src/compiler/compile/utils/get_object.ts rename src/compiler/compile/utils/{hash.ts => hash.js} (77%) rename src/compiler/compile/utils/{is_used_as_reference.ts => is_used_as_reference.js} (63%) create mode 100644 src/compiler/compile/utils/replace_object.js delete mode 100644 src/compiler/compile/utils/replace_object.ts rename src/compiler/compile/utils/{reserved_keywords.ts => reserved_keywords.js} (85%) rename src/compiler/compile/utils/{scope.ts => scope.js} (63%) create mode 100644 src/compiler/compile/utils/string_to_member_expression.js delete mode 100644 src/compiler/compile/utils/string_to_member_expression.ts rename src/compiler/compile/utils/{stringify.ts => stringify.js} (67%) diff --git a/src/compiler/compile/utils/__test__.ts b/src/compiler/compile/utils/__test__.js similarity index 68% rename from src/compiler/compile/utils/__test__.ts rename to src/compiler/compile/utils/__test__.js index fda8c8ee77..02b016de72 100644 --- a/src/compiler/compile/utils/__test__.ts +++ b/src/compiler/compile/utils/__test__.js @@ -1,14 +1,14 @@ import * as assert from 'assert'; -import get_name_from_filename from './get_name_from_filename'; +import get_name_from_filename from './get_name_from_filename.js'; import { is_contenteditable, has_contenteditable_attr, is_name_contenteditable, get_contenteditable_attr, CONTENTEDITABLE_BINDINGS -} from './contenteditable'; -import Element from '../nodes/Element'; -import Attribute from '../nodes/Attribute'; +} from './contenteditable.js'; +import Element from '../nodes/Element.js'; +import Attribute from '../nodes/Attribute.js'; describe('get_name_from_filename', () => { it('uses the basename', () => { @@ -33,34 +33,34 @@ describe('get_name_from_filename', () => { describe('contenteditable', () => { describe('is_contenteditable', () => { it('returns false if node is input', () => { - const node = { name: 'input' } as Element; + const node = /** @type {Element} */ ({ name: 'input' }); assert.equal(is_contenteditable(node), false); }); it('returns false if node is textarea', () => { - const node = { name: 'textarea' } as Element; + const node = /** @type {Element} */ ({ name: 'textarea' }); assert.equal(is_contenteditable(node), false); }); it('returns false if node is not input or textarea AND it is not contenteditable', () => { - const attr = { name: 'href' } as Attribute; - const node = { name: 'a', attributes: [attr] } as Element; + const attr = /** @type {Attribute} */ ({ name: 'href' }); + const node = /** @type {Element} */ ({ name: 'a', attributes: [attr] }); assert.equal(is_contenteditable(node), false); }); it('returns true if node is not input or textarea AND it is contenteditable', () => { - const attr = { name: 'contenteditable' } as Attribute; - const node = { name: 'a', attributes: [attr] } as Element; + const attr = /** @type {Attribute} */ ({ name: 'contenteditable' }); + const node = /** @type {Element} */ ({ name: 'a', attributes: [attr] }); assert.equal(is_contenteditable(node), true); }); }); describe('has_contenteditable_attr', () => { it('returns true if attribute is contenteditable', () => { - const attr = { name: 'contenteditable' } as Attribute; - const node = { attributes: [attr] } as Element; + const attr = /** @type {Attribute} */ ({ name: 'contenteditable' }); + const node = /** @type {Element} */ ({ attributes: [attr] }); assert.equal(has_contenteditable_attr(node), true); }); it('returns false if attribute is not contenteditable', () => { - const attr = { name: 'href' } as Attribute; - const node = { attributes: [attr] } as Element; + const attr = /** @type {Attribute} */ ({ name: 'href' }); + const node = /** @type {Element} */ ({ attributes: [attr] }); assert.equal(has_contenteditable_attr(node), false); }); }); @@ -76,12 +76,12 @@ describe('contenteditable', () => { describe('get_contenteditable_attr', () => { it('returns the contenteditable Attribute if it exists', () => { - const attr = { name: 'contenteditable' } as Attribute; - const node = { name: 'div', attributes: [attr] } as Element; + const attr = /** @type {Attribute} */ ({ name: 'contenteditable' }); + const node = /** @type {Element} */ ({ name: 'div', attributes: [attr] }); assert.equal(get_contenteditable_attr(node), attr); }); it('returns undefined if contenteditable attribute cannot be found', () => { - const node = { name: 'div', attributes: [] } as Element; + const node = /** @type {Element} */ ({ name: 'div', attributes: [] }); assert.equal(get_contenteditable_attr(node), undefined); }); }); diff --git a/src/compiler/compile/utils/add_to_set.js b/src/compiler/compile/utils/add_to_set.js new file mode 100644 index 0000000000..9a7a3be33f --- /dev/null +++ b/src/compiler/compile/utils/add_to_set.js @@ -0,0 +1,11 @@ +/** + * @template T + * @param {Set} a + * @param {Set | T[]} b + */ +export default function add_to_set(a, b) { + // @ts-ignore + b.forEach((item) => { + a.add(item); + }); +} diff --git a/src/compiler/compile/utils/add_to_set.ts b/src/compiler/compile/utils/add_to_set.ts deleted file mode 100644 index 220631b25d..0000000000 --- a/src/compiler/compile/utils/add_to_set.ts +++ /dev/null @@ -1,6 +0,0 @@ -export default function add_to_set(a: Set, b: Set | T[]) { - // @ts-ignore - b.forEach((item) => { - a.add(item); - }); -} diff --git a/src/compiler/compile/utils/check_enable_sourcemap.js b/src/compiler/compile/utils/check_enable_sourcemap.js new file mode 100644 index 0000000000..e18ec80e53 --- /dev/null +++ b/src/compiler/compile/utils/check_enable_sourcemap.js @@ -0,0 +1,7 @@ +/** + * @param {import("../../interfaces.js").EnableSourcemap} enable_sourcemap + * @param {keyof Extract} namespace + */ +export default function check_enable_sourcemap(enable_sourcemap, namespace) { + return typeof enable_sourcemap === 'boolean' ? enable_sourcemap : enable_sourcemap[namespace]; +} diff --git a/src/compiler/compile/utils/check_enable_sourcemap.ts b/src/compiler/compile/utils/check_enable_sourcemap.ts deleted file mode 100644 index 09262278be..0000000000 --- a/src/compiler/compile/utils/check_enable_sourcemap.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { EnableSourcemap } from '../../interfaces'; - -export default function check_enable_sourcemap( - enable_sourcemap: EnableSourcemap, - namespace: keyof Extract -) { - return typeof enable_sourcemap === 'boolean' ? enable_sourcemap : enable_sourcemap[namespace]; -} diff --git a/src/compiler/compile/utils/check_graph_for_cycles.ts b/src/compiler/compile/utils/check_graph_for_cycles.js similarity index 73% rename from src/compiler/compile/utils/check_graph_for_cycles.ts rename to src/compiler/compile/utils/check_graph_for_cycles.js index e503a5690e..e16e5e04df 100644 --- a/src/compiler/compile/utils/check_graph_for_cycles.ts +++ b/src/compiler/compile/utils/check_graph_for_cycles.js @@ -1,5 +1,10 @@ -export default function check_graph_for_cycles(edges: Array<[any, any]>): any[] { - const graph: Map = edges.reduce((g, edge) => { +/** + * @param {Array<[any, any]>} edges + * @returns {any[]} + */ +export default function check_graph_for_cycles(edges) { + /** @type {Map} */ + const graph = edges.reduce((g, edge) => { const [u, v] = edge; if (!g.has(u)) g.set(u, []); if (!g.has(v)) g.set(v, []); diff --git a/src/compiler/compile/utils/collapse_template_literal.ts b/src/compiler/compile/utils/collapse_template_literal.js similarity index 84% rename from src/compiler/compile/utils/collapse_template_literal.ts rename to src/compiler/compile/utils/collapse_template_literal.js index d99e3d0657..05492b5f75 100644 --- a/src/compiler/compile/utils/collapse_template_literal.ts +++ b/src/compiler/compile/utils/collapse_template_literal.js @@ -1,10 +1,10 @@ -import { TemplateLiteral } from 'estree'; -import { escape_template } from './stringify'; +import { escape_template } from './stringify.js'; /** * Collapse string literals together + * @param {import('estree').TemplateLiteral} literal */ -export function collapse_template_literal(literal: TemplateLiteral) { +export function collapse_template_literal(literal) { if (!literal.quasis.length) return; const collapsed_quasis = []; diff --git a/src/compiler/compile/utils/compare_node.js b/src/compiler/compile/utils/compare_node.js new file mode 100644 index 0000000000..12eb008df1 --- /dev/null +++ b/src/compiler/compile/utils/compare_node.js @@ -0,0 +1,21 @@ +/** + * @param {import('estree').Node | void} a + * @param {import('estree').Node | void} b + */ +export function compare_node(a, b) { + if (a === b) return true; + if (!a || !b) return false; + if (a.type !== b.type) return false; + switch (a.type) { + case 'Identifier': + return a.name === /** @type {import('estree').Identifier} */ (b).name; + case 'MemberExpression': + return ( + compare_node(a.object, /** @type {import('estree').MemberExpression} */ (b).object) && + compare_node(a.property, /** @type {import('estree').MemberExpression} */ (b).property) && + a.computed === /** @type {import('estree').MemberExpression} */ (b).computed + ); + case 'Literal': + return a.value === /** @type {import('estree').Literal} */ (b).value; + } +} diff --git a/src/compiler/compile/utils/compare_node.ts b/src/compiler/compile/utils/compare_node.ts deleted file mode 100644 index 3cd9321ea9..0000000000 --- a/src/compiler/compile/utils/compare_node.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { Node, Literal, Identifier, MemberExpression } from 'estree'; - -export function compare_node(a: Node | void, b: Node | void) { - if (a === b) return true; - if (!a || !b) return false; - if (a.type !== b.type) return false; - switch (a.type) { - case 'Identifier': - return a.name === (b as Identifier).name; - case 'MemberExpression': - return ( - compare_node(a.object, (b as MemberExpression).object) && - compare_node(a.property, (b as MemberExpression).property) && - a.computed === (b as MemberExpression).computed - ); - case 'Literal': - return a.value === (b as Literal).value; - } -} diff --git a/src/compiler/compile/utils/contenteditable.ts b/src/compiler/compile/utils/contenteditable.js similarity index 72% rename from src/compiler/compile/utils/contenteditable.ts rename to src/compiler/compile/utils/contenteditable.js index a4c7b8fcfb..bb49b9ee80 100644 --- a/src/compiler/compile/utils/contenteditable.ts +++ b/src/compiler/compile/utils/contenteditable.js @@ -1,6 +1,6 @@ // Utilities for managing contenteditable nodes -import Attribute from '../nodes/Attribute'; -import Element from '../nodes/Element'; +import Attribute from '../nodes/Attribute.js'; +import Element from '../nodes/Element.js'; export const CONTENTEDITABLE_BINDINGS = ['textContent', 'innerHTML', 'innerText']; @@ -8,7 +8,7 @@ export const CONTENTEDITABLE_BINDINGS = ['textContent', 'innerHTML', 'innerText' * Returns true if node is an 'input' or 'textarea'. * @param {Element} node The element to be checked */ -function is_input_or_textarea(node: Element): boolean { +function is_input_or_textarea(node) { return node.name === 'textarea' || node.name === 'input'; } @@ -16,7 +16,7 @@ function is_input_or_textarea(node: Element): boolean { * Check if a given attribute is 'contenteditable'. * @param {Attribute} attribute A node.attribute */ -function is_attr_contenteditable(attribute: Attribute): boolean { +function is_attr_contenteditable(attribute) { return attribute.name === 'contenteditable'; } @@ -24,7 +24,7 @@ function is_attr_contenteditable(attribute: Attribute): boolean { * Check if any of a node's attributes are 'contentenditable'. * @param {Element} node The element to be checked */ -export function has_contenteditable_attr(node: Element): boolean { +export function has_contenteditable_attr(node) { return node.attributes.some(is_attr_contenteditable); } @@ -32,7 +32,7 @@ export function has_contenteditable_attr(node: Element): boolean { * Returns true if node is not textarea or input, but has 'contenteditable' attribute. * @param {Element} node The element to be tested */ -export function is_contenteditable(node: Element): boolean { +export function is_contenteditable(node) { return !is_input_or_textarea(node) && has_contenteditable_attr(node); } @@ -40,7 +40,7 @@ export function is_contenteditable(node: Element): boolean { * Returns true if a given binding/node is contenteditable. * @param {string} name A binding or node name to be checked */ -export function is_name_contenteditable(name: string): boolean { +export function is_name_contenteditable(name) { return CONTENTEDITABLE_BINDINGS.includes(name); } @@ -48,6 +48,6 @@ export function is_name_contenteditable(name: string): boolean { * Returns the contenteditable attribute from the node (if it exists). * @param {Element} node The element to get the attribute from */ -export function get_contenteditable_attr(node: Element): Attribute | undefined { +export function get_contenteditable_attr(node) { return node.attributes.find(is_attr_contenteditable); } diff --git a/src/compiler/compile/utils/flatten_reference.ts b/src/compiler/compile/utils/flatten_reference.js similarity index 70% rename from src/compiler/compile/utils/flatten_reference.ts rename to src/compiler/compile/utils/flatten_reference.js index bef886b587..53b9f24b7e 100644 --- a/src/compiler/compile/utils/flatten_reference.ts +++ b/src/compiler/compile/utils/flatten_reference.js @@ -1,6 +1,7 @@ -import { Node, Identifier } from 'estree'; - -export default function flatten_reference(node: Node) { +/** + * @param {import('estree').Node} node + */ +export default function flatten_reference(node) { const nodes = []; const parts = []; @@ -8,7 +9,7 @@ export default function flatten_reference(node: Node) { nodes.unshift(node.property); if (!node.computed) { - parts.unshift((node.property as Identifier).name); + parts.unshift(/** @type {import('estree').Identifier} */ (node.property).name); } else { const computed_property = to_string(node.property); if (computed_property) { @@ -28,7 +29,10 @@ export default function flatten_reference(node: Node) { return { name, nodes, parts }; } -function to_string(node: Node) { +/** + * @param {import('estree').Node} node + */ +function to_string(node) { switch (node.type) { case 'Literal': return String(node.value); diff --git a/src/compiler/compile/utils/get_name_from_filename.ts b/src/compiler/compile/utils/get_name_from_filename.js similarity index 91% rename from src/compiler/compile/utils/get_name_from_filename.ts rename to src/compiler/compile/utils/get_name_from_filename.js index dd28190d80..3931d1ae6e 100644 --- a/src/compiler/compile/utils/get_name_from_filename.ts +++ b/src/compiler/compile/utils/get_name_from_filename.js @@ -4,7 +4,10 @@ const regex_repeated_invalid_variable_identifier_characters = /[^a-zA-Z_$0-9]+/g const regex_starts_with_digit = /^(\d)/; const regex_may_starts_or_ends_with_underscore = /^_?(.+?)_?$/; -export default function get_name_from_filename(filename: string) { +/** + * @param {string} filename + */ +export default function get_name_from_filename(filename) { if (!filename) return null; const parts = filename.split(/[/\\]/).map(encodeURI); diff --git a/src/compiler/compile/utils/get_object.js b/src/compiler/compile/utils/get_object.js new file mode 100644 index 0000000000..f87ced1019 --- /dev/null +++ b/src/compiler/compile/utils/get_object.js @@ -0,0 +1,7 @@ +/** + * @param {import('estree').Node} node + */ +export default function get_object(node) { + while (node.type === 'MemberExpression') node = node.object; + return /** @type {import('estree').Identifier} */ (node); +} diff --git a/src/compiler/compile/utils/get_object.ts b/src/compiler/compile/utils/get_object.ts deleted file mode 100644 index 863bfb0d61..0000000000 --- a/src/compiler/compile/utils/get_object.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Node, Identifier } from 'estree'; - -export default function get_object(node: Node): Identifier { - while (node.type === 'MemberExpression') node = node.object; - return node as Identifier; -} diff --git a/src/compiler/compile/utils/hash.ts b/src/compiler/compile/utils/hash.js similarity index 77% rename from src/compiler/compile/utils/hash.ts rename to src/compiler/compile/utils/hash.js index d5b5a20609..dbfcbdd356 100644 --- a/src/compiler/compile/utils/hash.ts +++ b/src/compiler/compile/utils/hash.js @@ -2,7 +2,11 @@ const regex_return_characters = /\r/g; -export default function hash(str: string): string { +/** + * @param {string} str + * @returns {string} + */ +export default function hash(str) { str = str.replace(regex_return_characters, ''); let hash = 5381; let i = str.length; diff --git a/src/compiler/compile/utils/is_used_as_reference.ts b/src/compiler/compile/utils/is_used_as_reference.js similarity index 63% rename from src/compiler/compile/utils/is_used_as_reference.ts rename to src/compiler/compile/utils/is_used_as_reference.js index c1362be40d..95560804b2 100644 --- a/src/compiler/compile/utils/is_used_as_reference.ts +++ b/src/compiler/compile/utils/is_used_as_reference.js @@ -1,8 +1,18 @@ -import { Node } from 'estree'; -import is_reference, { NodeWithPropertyDefinition } from 'is-reference'; +import is_reference from 'is-reference'; -export default function is_used_as_reference(node: Node, parent: Node): boolean { - if (!is_reference(node as NodeWithPropertyDefinition, parent as NodeWithPropertyDefinition)) { +/** + * + * @param {import('estree').Node} node + * @param {import('estree').Node} parent + * @returns {boolean} + */ +export default function is_used_as_reference(node, parent) { + if ( + !is_reference( + /** @type {import('is-reference').NodeWithPropertyDefinition} */ (node), + /** @type {import('is-reference').NodeWithPropertyDefinition} */ (parent) + ) + ) { return false; } if (!parent) { diff --git a/src/compiler/compile/utils/replace_object.js b/src/compiler/compile/utils/replace_object.js new file mode 100644 index 0000000000..11bd3ba736 --- /dev/null +++ b/src/compiler/compile/utils/replace_object.js @@ -0,0 +1,16 @@ +/** + * @param {import('estree').Node} node + * @param {import('estree').Node} replacement + */ +export default function replace_object(node, replacement) { + if (node.type === 'Identifier') return replacement; + + const ancestor = node; + let parent; + while (node.type === 'MemberExpression') { + parent = node; + node = node.object; + } + parent.object = /** @type {any} */ (replacement); + return ancestor; +} diff --git a/src/compiler/compile/utils/replace_object.ts b/src/compiler/compile/utils/replace_object.ts deleted file mode 100644 index 2de1dbc24a..0000000000 --- a/src/compiler/compile/utils/replace_object.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Node } from 'estree'; - -export default function replace_object(node: Node, replacement: Node) { - if (node.type === 'Identifier') return replacement; - - const ancestor = node; - let parent; - while (node.type === 'MemberExpression') { - parent = node; - node = node.object; - } - parent.object = replacement; - return ancestor; -} diff --git a/src/compiler/compile/utils/reserved_keywords.ts b/src/compiler/compile/utils/reserved_keywords.js similarity index 85% rename from src/compiler/compile/utils/reserved_keywords.ts rename to src/compiler/compile/utils/reserved_keywords.js index a68819a493..1ff1fbc8cf 100644 --- a/src/compiler/compile/utils/reserved_keywords.ts +++ b/src/compiler/compile/utils/reserved_keywords.js @@ -1,5 +1,6 @@ export const reserved_keywords = new Set(['$$props', '$$restProps', '$$slots']); +/** @param {string} name */ export function is_reserved_keyword(name) { return reserved_keywords.has(name); } diff --git a/src/compiler/compile/utils/scope.ts b/src/compiler/compile/utils/scope.js similarity index 63% rename from src/compiler/compile/utils/scope.ts rename to src/compiler/compile/utils/scope.js index e103defa4d..3656f18e6c 100644 --- a/src/compiler/compile/utils/scope.ts +++ b/src/compiler/compile/utils/scope.js @@ -1,7 +1,9 @@ -import { Node } from 'estree'; import { analyze, Scope, extract_names, extract_identifiers } from 'periscopic'; -export function create_scopes(expression: Node) { +/** + * @param {import('estree').Node} expression + */ +export function create_scopes(expression) { return analyze(expression); } diff --git a/src/compiler/compile/utils/string_to_member_expression.js b/src/compiler/compile/utils/string_to_member_expression.js new file mode 100644 index 0000000000..0cbb31b5ec --- /dev/null +++ b/src/compiler/compile/utils/string_to_member_expression.js @@ -0,0 +1,19 @@ +/** + * @param {string} name + */ +export function string_to_member_expression(name) { + const parts = name.split('.'); + /** @type {import('estree').MemberExpression | import('estree').Identifier} */ + let node = { + type: 'Identifier', + name: parts[0] + }; + for (let i = 1; i < parts.length; i++) { + node = /** @type {import('estree').MemberExpression} */ ({ + type: 'MemberExpression', + object: node, + property: { type: 'Identifier', name: parts[i] } + }); + } + return node; +} diff --git a/src/compiler/compile/utils/string_to_member_expression.ts b/src/compiler/compile/utils/string_to_member_expression.ts deleted file mode 100644 index 783571b035..0000000000 --- a/src/compiler/compile/utils/string_to_member_expression.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { MemberExpression, Identifier } from 'estree'; - -export function string_to_member_expression(name: string) { - const parts = name.split('.'); - let node: MemberExpression | Identifier = { - type: 'Identifier', - name: parts[0] - }; - for (let i = 1; i < parts.length; i++) { - node = { - type: 'MemberExpression', - object: node, - property: { type: 'Identifier', name: parts[i] } - } as MemberExpression; - } - return node; -} diff --git a/src/compiler/compile/utils/stringify.ts b/src/compiler/compile/utils/stringify.js similarity index 67% rename from src/compiler/compile/utils/stringify.ts rename to src/compiler/compile/utils/stringify.js index 927d49581d..029568df24 100644 --- a/src/compiler/compile/utils/stringify.ts +++ b/src/compiler/compile/utils/stringify.js @@ -1,13 +1,19 @@ -import { Literal } from 'estree'; -export function string_literal(data: string): Literal { +/** + * @param {string} data + * @returns {import('estree').Literal} + */ +export function string_literal(data) { return { type: 'Literal', value: data }; } - -export function escape(data: string, { only_escape_at_symbol = false } = {}) { - return data.replace(only_escape_at_symbol ? /@+/g : /(@+|#+)/g, (match: string) => { +/** + * @param {string} data + * @param {{ only_escape_at_symbol?: boolean }} [options] + */ +export function escape(data, { only_escape_at_symbol = false } = {}) { + return data.replace(only_escape_at_symbol ? /@+/g : /(@+|#+)/g, (match) => { return match + match[0]; }); }