Skip to content

Commit 5701e8a

Browse files
committed
fix: change camel-case declarations to snake-case
1 parent 3825adb commit 5701e8a

File tree

21 files changed

+136
-122
lines changed

21 files changed

+136
-122
lines changed

packages/svelte/scripts/compile-test.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
// Compile all Svelte files in a directory to JS and CSS files
22
// Usage: node scripts/compile-test.js <directory>
33

4-
import { mkdirSync, readFileSync, writeFileSync } from 'fs';
5-
import path from 'path';
6-
import glob from 'tiny-glob/sync.js';
4+
import {
5+
mkdirSync as mkdir_sync,
6+
readFileSync as read_file_sync,
7+
writeFileSync as write_file_sync
8+
} from 'fs';
9+
710
import { compile } from '../src/compiler/index.js';
11+
import glob from 'tiny-glob/sync.js';
12+
import path from 'path';
813

914
const cwd = path.resolve(process.argv[2]);
1015

@@ -14,7 +19,7 @@ const options = [
1419
['ssr', { generate: 'ssr' }]
1520
];
1621
for (const file of glob('**/*.svelte', { cwd })) {
17-
const contents = readFileSync(`${cwd}/${file}`, 'utf-8').replace(/\r/g, '');
22+
const contents = read_file_sync(`${cwd}/${file}`, 'utf-8').replace(/\r/g, '');
1823
let w;
1924
for (const [name, opts] of options) {
2025
const dir = `${cwd}/_output/${name}`;
@@ -28,9 +33,9 @@ for (const file of glob('**/*.svelte', { cwd })) {
2833
w = warnings;
2934
}
3035

31-
mkdirSync(dir, { recursive: true });
32-
js.code && writeFileSync(`${dir}/${file.replace(/\.svelte$/, '.js')}`, js.code);
33-
css.code && writeFileSync(`${dir}/${file.replace(/\.svelte$/, '.css')}`, css.code);
36+
mkdir_sync(dir, { recursive: true });
37+
js.code && write_file_sync(`${dir}/${file.replace(/\.svelte$/, '.js')}`, js.code);
38+
css.code && write_file_sync(`${dir}/${file.replace(/\.svelte$/, '.css')}`, css.code);
3439
}
3540

3641
if (w) {

packages/svelte/scripts/generate-dts.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as fs from 'fs';
2-
import { createBundle } from 'dts-buddy';
2+
3+
import { createBundle as create_bundle } from 'dts-buddy';
34

45
// It may look weird, but the imports MUST be ending with index.js to be properly resolved in all TS modes
56
for (const name of ['action', 'animate', 'easing', 'motion', 'store', 'transition']) {
@@ -14,7 +15,7 @@ fs.mkdirSync('./types/compiler', { recursive: true });
1415
fs.writeFileSync('./types/compiler/preprocess.d.ts', `import '../index.js';`);
1516
fs.writeFileSync('./types/compiler/interfaces.d.ts', `import '../index.js';`);
1617

17-
await createBundle({
18+
await create_bundle({
1819
output: 'types/index.d.ts',
1920
compilerOptions: {
2021
strict: true

packages/svelte/src/compiler/compile/Component.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { TraceMap, originalPositionFor } from '@jridgewell/trace-mapping';
1+
import { TraceMap, originalPositionFor as original_position_for } from '@jridgewell/trace-mapping';
22
import { walk } from 'estree-walker';
3-
import { getLocator } from 'locate-character';
3+
import { getLocator as get_locator } from 'locate-character';
44
import { reserved, is_valid } from '../utils/names.js';
55
import globals from '../utils/globals.js';
66
import { namespaces, valid_namespaces } from '../utils/namespaces.js';
@@ -213,7 +213,7 @@ export default class Component {
213213
: compile_options.filename);
214214

215215
// line numbers in stack trace frames are 1-based. source maps are 0-based
216-
this.locate = getLocator(this.source, { offsetLine: 1 });
216+
this.locate = get_locator(this.source, { offsetLine: 1 });
217217
/** @type {TraceMap | null | undefined} initialise lazy because only used in dev mode */
218218
let tracer;
219219
this.meta_locate = (c) => {
@@ -225,7 +225,7 @@ export default class Component {
225225
}
226226
if (tracer) {
227227
// originalPositionFor returns 1-based lines like locator
228-
location = originalPositionFor(tracer, location);
228+
location = original_position_for(tracer, location);
229229
}
230230
return location;
231231
};
@@ -1555,8 +1555,8 @@ export default class Component {
15551555
}, [])
15561556
);
15571557
if (cycle && cycle.length) {
1558-
const declarationList = lookup.get(cycle[0]);
1559-
const declaration = declarationList[0];
1558+
const declaration_list = lookup.get(cycle[0]);
1559+
const declaration = declaration_list[0];
15601560
return this.error(declaration.node, compiler_errors.cyclical_reactive_declaration(cycle));
15611561
}
15621562

packages/svelte/src/compiler/compile/create_module.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ export default function create_module(
4141

4242
/**
4343
* @param {any} source
44-
* @param {any} sveltePath
44+
* @param {any} svelte_path
4545
*/
46-
function edit_source(source, sveltePath) {
46+
function edit_source(source, svelte_path) {
4747
return source === 'svelte' || source.startsWith('svelte/')
48-
? source.replace('svelte', sveltePath)
48+
? source.replace('svelte', svelte_path)
4949
: source;
5050
}
5151

@@ -84,7 +84,7 @@ function get_internal_globals(globals, helpers) {
8484
* @param {any} program
8585
* @param {import('estree').Identifier} name
8686
* @param {string} banner
87-
* @param {string} sveltePath
87+
* @param {string} svelte_path
8888
* @param {string} internal_path
8989
* @param {Array<{ name: string; alias: import('estree').Identifier }>} helpers
9090
* @param {Array<{ name: string; alias: import('estree').Identifier }>} globals
@@ -96,7 +96,7 @@ function esm(
9696
program,
9797
name,
9898
banner,
99-
sveltePath,
99+
svelte_path,
100100
internal_path,
101101
helpers,
102102
globals,
@@ -118,7 +118,7 @@ function esm(
118118

119119
/** @param {any} node */
120120
function rewrite_import(node) {
121-
const value = edit_source(node.source.value, sveltePath);
121+
const value = edit_source(node.source.value, svelte_path);
122122
if (node.source.value !== value) {
123123
node.source.value = value;
124124
node.source.raw = null;

packages/svelte/src/compiler/compile/nodes/Binding.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export default class Binding extends Node {
9898
this.is_readonly =
9999
regex_dimensions.test(this.name) ||
100100
regex_box_size.test(this.name) ||
101-
(isElement(parent) &&
101+
(is_element(parent) &&
102102
((parent.is_media_node() && read_only_media_attributes.has(this.name)) ||
103103
(parent.name === 'input' && type === 'file'))) /* TODO others? */;
104104
}
@@ -127,6 +127,6 @@ export default class Binding extends Node {
127127
* @param {import('./shared/Node.js').default} node
128128
* @returns {node is import('./Element.js').default}
129129
*/
130-
function isElement(node) {
130+
function is_element(node) {
131131
return !!(/** @type {any} */ (node).is_media_node);
132132
}

packages/svelte/src/compiler/compile/nodes/EachBlock.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ export default class EachBlock extends AbstractBlock {
8484
this.has_animation = false;
8585
[this.const_tags, this.children] = get_const_tags(info.children, component, this, this);
8686
if (this.has_animation) {
87-
this.children = this.children.filter((child) => !isEmptyNode(child) && !isCommentNode(child));
87+
this.children = this.children.filter(
88+
(child) => !is_empty_node(child) && !is_comment_node(child)
89+
);
8890
if (this.children.length !== 1) {
8991
const child = this.children.find(
9092
(child) => !!(/** @type {import('./Element.js').default} */ (child).animation)
@@ -102,11 +104,11 @@ export default class EachBlock extends AbstractBlock {
102104
}
103105

104106
/** @param {import('./interfaces.js').INode} node */
105-
function isEmptyNode(node) {
107+
function is_empty_node(node) {
106108
return node.type === 'Text' && node.data.trim() === '';
107109
}
108110

109111
/** @param {import('./interfaces.js').INode} node */
110-
function isCommentNode(node) {
112+
function is_comment_node(node) {
111113
return node.type === 'Comment';
112114
}

packages/svelte/src/compiler/compile/nodes/shared/get_const_tags.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ function sort_consts_nodes(consts_nodes, component) {
7373
}, [])
7474
);
7575
if (cycle && cycle.length) {
76-
const nodeList = lookup.get(cycle[0]);
77-
const node = nodeList[0];
76+
const node_list = lookup.get(cycle[0]);
77+
const node = node_list[0];
7878
component.error(node.node, compiler_errors.cyclical_const_tags(cycle));
7979
}
8080

packages/svelte/src/compiler/compile/render_dom/wrappers/Window.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import Wrapper from './shared/Wrapper.js';
21
import { b, x } from 'code-red';
3-
import add_event_handlers from './shared/add_event_handlers.js';
4-
import add_actions from './shared/add_actions.js';
2+
53
import EventHandler from './Element/EventHandler.js';
4+
import Wrapper from './shared/Wrapper.js';
5+
import add_actions from './shared/add_actions.js';
6+
import add_event_handlers from './shared/add_event_handlers.js';
67

78
const associated_events = {
89
innerWidth: 'resize',
@@ -94,14 +95,14 @@ export default class WindowWrapper extends Wrapper {
9495
bindings.scrollX && bindings.scrollY
9596
? x`"${bindings.scrollX}" in this._state || "${bindings.scrollY}" in this._state`
9697
: x`"${bindings.scrollX || bindings.scrollY}" in this._state`;
97-
const scrollX = bindings.scrollX && x`this._state.${bindings.scrollX}`;
98-
const scrollY = bindings.scrollY && x`this._state.${bindings.scrollY}`;
98+
const scroll_x = bindings.scrollX && x`this._state.${bindings.scrollX}`;
99+
const scroll_y = bindings.scrollY && x`this._state.${bindings.scrollY}`;
99100
renderer.meta_bindings.push(b`
100101
if (${condition}) {
101-
@_scrollTo(${scrollX || '@_window.pageXOffset'}, ${scrollY || '@_window.pageYOffset'});
102+
@_scrollTo(${scroll_x || '@_window.pageXOffset'}, ${scroll_y || '@_window.pageYOffset'});
102103
}
103-
${scrollX && `${scrollX} = @_window.pageXOffset;`}
104-
${scrollY && `${scrollY} = @_window.pageYOffset;`}
104+
${scroll_x && `${scroll_x} = @_window.pageXOffset;`}
105+
${scroll_y && `${scroll_y} = @_window.pageYOffset;`}
105106
`);
106107
block.event_listeners.push(x`
107108
@listen(@_window, "${event}", () => {
@@ -132,17 +133,17 @@ export default class WindowWrapper extends Wrapper {
132133
// special case... might need to abstract this out if we add more special cases
133134
if (bindings.scrollX || bindings.scrollY) {
134135
const condition = renderer.dirty([bindings.scrollX, bindings.scrollY].filter(Boolean));
135-
const scrollX = bindings.scrollX
136+
const scroll_x = bindings.scrollX
136137
? renderer.reference(bindings.scrollX)
137138
: x`@_window.pageXOffset`;
138-
const scrollY = bindings.scrollY
139+
const scroll_y = bindings.scrollY
139140
? renderer.reference(bindings.scrollY)
140141
: x`@_window.pageYOffset`;
141142
block.chunks.update.push(b`
142143
if (${condition} && !${scrolling}) {
143144
${scrolling} = true;
144145
@_clearTimeout(${scrolling_timeout});
145-
@_scrollTo(${scrollX}, ${scrollY});
146+
@_scrollTo(${scroll_x}, ${scroll_y});
146147
${scrolling_timeout} = @_setTimeout(${clear_scrolling}, 100);
147148
}
148149
`);

packages/svelte/src/compiler/compile/utils/a11y.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { roles as roles_map, elementRoles } from 'aria-query';
2-
import { AXObjects, AXObjectRoles, elementAXObjects } from 'axobject-query';
1+
import { roles as roles_map, elementRoles as element_roles } from 'aria-query';
2+
import { AXObjects, AXObjectRoles, elementAXObjects as element_ax_objects } from 'axobject-query';
33
import { regex_whitespaces } from '../../utils/patterns.js';
44

55
const aria_roles = roles_map.keys();
@@ -104,7 +104,7 @@ export function has_disabled_attribute(attribute_map) {
104104
* @type {import('aria-query').ARIARoleRelationConcept[]}
105105
*/
106106
const non_interactive_element_role_schemas = [];
107-
elementRoles.entries().forEach(([schema, roles]) => {
107+
element_roles.entries().forEach(([schema, roles]) => {
108108
if ([...roles].every((role) => role !== 'generic' && non_interactive_roles.has(role))) {
109109
non_interactive_element_role_schemas.push(schema);
110110
}
@@ -114,7 +114,7 @@ elementRoles.entries().forEach(([schema, roles]) => {
114114
* @type {import('aria-query').ARIARoleRelationConcept[]}
115115
*/
116116
const interactive_element_role_schemas = [];
117-
elementRoles.entries().forEach(([schema, roles]) => {
117+
element_roles.entries().forEach(([schema, roles]) => {
118118
if ([...roles].every((role) => interactive_roles.has(role))) {
119119
interactive_element_role_schemas.push(schema);
120120
}
@@ -132,7 +132,7 @@ const non_interactive_ax_objects = new Set(
132132
* @type {import('aria-query').ARIARoleRelationConcept[]}
133133
*/
134134
const interactive_element_ax_object_schemas = [];
135-
elementAXObjects.entries().forEach(([schema, ax_object]) => {
135+
element_ax_objects.entries().forEach(([schema, ax_object]) => {
136136
if ([...ax_object].every((role) => interactive_ax_objects.has(role))) {
137137
interactive_element_ax_object_schemas.push(schema);
138138
}
@@ -142,7 +142,7 @@ elementAXObjects.entries().forEach(([schema, ax_object]) => {
142142
* @type {import('aria-query').ARIARoleRelationConcept[]}
143143
*/
144144
const non_interactive_element_ax_object_schemas = [];
145-
elementAXObjects.entries().forEach(([schema, ax_object]) => {
145+
element_ax_objects.entries().forEach(([schema, ax_object]) => {
146146
if ([...ax_object].every((role) => non_interactive_ax_objects.has(role))) {
147147
non_interactive_element_ax_object_schemas.push(schema);
148148
}
@@ -241,7 +241,7 @@ export function is_static_element(tag_name, attribute_map) {
241241
* @param {Map<string, import('../nodes/Attribute.js').default>} attribute_map
242242
*/
243243
export function is_semantic_role_element(role, tag_name, attribute_map) {
244-
for (const [schema, ax_object] of elementAXObjects.entries()) {
244+
for (const [schema, ax_object] of element_ax_objects.entries()) {
245245
if (
246246
schema.name === tag_name &&
247247
(!schema.attributes ||

packages/svelte/src/compiler/parse/read/context.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isIdentifierStart } from 'acorn';
1+
import { isIdentifierStart as is_identifier_start } from 'acorn';
22
import full_char_code_at from '../../utils/full_char_code_at.js';
33
import {
44
is_bracket_open,
@@ -19,7 +19,7 @@ export default function read_context(parser) {
1919
let i = parser.index;
2020

2121
const code = full_char_code_at(parser.template, i);
22-
if (isIdentifierStart(code, true)) {
22+
if (is_identifier_start(code, true)) {
2323
return {
2424
type: 'Identifier',
2525
name: parser.read_identifier(),

0 commit comments

Comments
 (0)