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: upgrade magic-string #8339

Merged
merged 7 commits into from
Mar 2, 2023
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
21 changes: 12 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"jsdom": "^15.2.1",
"kleur": "^4.1.5",
"locate-character": "^2.0.5",
"magic-string": "^0.25.3",
"magic-string": "^0.30.0",
"mocha": "^7.0.0",
"periscopic": "^3.0.4",
"puppeteer": "^2.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/compile/css/Selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default class Selector {
this.blocks.forEach((block, i) => {
if (i > 0) {
if (block.start - c > 1) {
code.overwrite(c, block.start, block.combinator.name || ' ');
code.update(c, block.start, block.combinator.name || ' ');
}
}

Expand Down Expand Up @@ -112,7 +112,7 @@ export default class Selector {
}

if (selector.type === 'TypeSelector' && selector.name === '*') {
code.overwrite(selector.start, selector.end, attr);
code.update(selector.start, selector.end, attr);
} else {
code.appendLeft(selector.end, attr);
}
Expand Down
14 changes: 7 additions & 7 deletions src/compiler/compile/css/Stylesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function minify_declarations(
declarations.forEach((declaration, i) => {
const separator = i > 0 ? ';' : '';
if ((declaration.node.start - c) > separator.length) {
code.overwrite(c, declaration.node.start, separator);
code.update(c, declaration.node.start, separator);
}
declaration.minify(code);
c = declaration.node.end;
Expand Down Expand Up @@ -75,7 +75,7 @@ class Rule {
if (selector.used) {
const separator = started ? ',' : '';
if ((selector.node.start - c) > separator.length) {
code.overwrite(c, selector.node.start, separator);
code.update(c, selector.node.start, separator);
}

selector.minify(code);
Expand Down Expand Up @@ -133,7 +133,7 @@ class Declaration {
if (block.type === 'Identifier') {
const name = block.name;
if (keyframes.has(name)) {
code.overwrite(block.start, block.end, keyframes.get(name));
code.update(block.start, block.end, keyframes.get(name));
}
}
});
Expand All @@ -156,7 +156,7 @@ class Declaration {
while (regex_whitespace.test(code.original[start])) start += 1;

if (start - c > 1) {
code.overwrite(c, start, ':');
code.update(c, start, ':');
}
}
}
Expand Down Expand Up @@ -204,7 +204,7 @@ class Atrule {
code.remove(c, this.node.block.start);
} else if (this.node.name === 'supports') {
let c = this.node.start + 9;
if (this.node.prelude.start - c > 1) code.overwrite(c, this.node.prelude.start, ' ');
if (this.node.prelude.start - c > 1) code.update(c, this.node.prelude.start, ' ');
this.node.prelude.children.forEach((query: CssNode) => {
// TODO minify queries
c = query.end;
Expand All @@ -213,7 +213,7 @@ class Atrule {
} else {
let c = this.node.start + this.node.name.length + 1;
if (this.node.prelude) {
if (this.node.prelude.start - c > 1) code.overwrite(c, this.node.prelude.start, ' ');
if (this.node.prelude.start - c > 1) code.update(c, this.node.prelude.start, ' ');
c = this.node.prelude.end;
}
if (this.node.block && this.node.block.start - c > 0) {
Expand Down Expand Up @@ -255,7 +255,7 @@ class Atrule {
});
});
} else {
code.overwrite(start, end, keyframes.get(name));
code.update(start, end, keyframes.get(name));
}
}
});
Expand Down
9 changes: 6 additions & 3 deletions test/sourcemaps/samples/compile-option-dev/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ export async function test({ assert, css, js }) {
// TODO make util fn + move to test index.js
const sourcefile = 'input.svelte';
[
// TODO how to get line + column numbers?
// TODO: get line and col num from input.svelte rather than hardcoding here
[css, '--keep-me', 13, 2],
[css, '--done-replace-once', 6, 5],
[css, '--done-replace-twice', 9, 5]
// TODO: these should be 7, 2 and 10, 2
// we use locate_1 which means lines are 1-indexed and cols are 0-indexed
// each tab is 1 col
[css, '--done-replace-once', 6, 4],
[css, '--done-replace-twice', 9, 4]
]
.forEach(([where, content, line, column]) => {
assert.deepEqual(
Expand Down