mirror of https://github.com/sveltejs/svelte
chore: move parser helpers next to their users (#18785)
Phase 1 imported `disallow_children` from phase 2, `fuzzymatch` sat in the parser's utils while only analysis and `extract_svelte_ignore` used it, `create_fragment` had a file to itself although `create_attribute` lives in `phases/nodes.js`, and `push_array` had a single caller. Each now sits next to its users: `create_fragment` and `disallow_children` in `phases/nodes.js`, `fuzzymatch` in `compiler/utils`, `push_array` inside `mapped_code.js`. Four files fewer, no behaviour change.pull/18812/head
parent
f2ad10ecd2
commit
5981c060d2
@ -1,16 +0,0 @@
|
||||
/** @import { AST } from '#compiler' */
|
||||
|
||||
/**
|
||||
* @param {any} transparent
|
||||
* @returns {AST.Fragment}
|
||||
*/
|
||||
export function create_fragment(transparent = false) {
|
||||
return {
|
||||
type: 'Fragment',
|
||||
nodes: [],
|
||||
metadata: {
|
||||
transparent,
|
||||
dynamic: false
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
/** @import { AST } from '#compiler' */
|
||||
import * as e from '../../../../errors.js';
|
||||
|
||||
/**
|
||||
* @param {AST.SvelteBody | AST.SvelteDocument | AST.SvelteOptionsRaw | AST.SvelteWindow} node
|
||||
*/
|
||||
export function disallow_children(node) {
|
||||
const { nodes } = node.fragment;
|
||||
|
||||
if (nodes.length > 0) {
|
||||
const first = nodes[0];
|
||||
const last = nodes[nodes.length - 1];
|
||||
|
||||
e.svelte_meta_invalid_content({ start: first.start, end: last.end }, node.name);
|
||||
}
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
/**
|
||||
* Pushes all `items` into `array` using `push`, therefore mutating the array.
|
||||
* We do this for memory and perf reasons, and because `array.push(...items)` would
|
||||
* run into a "max call stack size exceeded" error with too many items (~65k).
|
||||
* @template T
|
||||
* @param {T[]} array
|
||||
* @param {T[]} items
|
||||
*/
|
||||
export function push_array(array, items) {
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
array.push(items[i]);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue