Skip to content

Commit 5b2fa1f

Browse files
authored
chore: upgrade magic-string (#8339)
- overwrite -> update - update comments
1 parent 0966d1d commit 5b2fa1f

File tree

5 files changed

+28
-22
lines changed

5 files changed

+28
-22
lines changed

package-lock.json

Lines changed: 12 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
"jsdom": "^15.2.1",
149149
"kleur": "^4.1.5",
150150
"locate-character": "^2.0.5",
151-
"magic-string": "^0.25.3",
151+
"magic-string": "^0.30.0",
152152
"mocha": "^7.0.0",
153153
"periscopic": "^3.0.4",
154154
"puppeteer": "^2.0.0",

src/compiler/compile/css/Selector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export default class Selector {
7676
this.blocks.forEach((block, i) => {
7777
if (i > 0) {
7878
if (block.start - c > 1) {
79-
code.overwrite(c, block.start, block.combinator.name || ' ');
79+
code.update(c, block.start, block.combinator.name || ' ');
8080
}
8181
}
8282

@@ -112,7 +112,7 @@ export default class Selector {
112112
}
113113

114114
if (selector.type === 'TypeSelector' && selector.name === '*') {
115-
code.overwrite(selector.start, selector.end, attr);
115+
code.update(selector.start, selector.end, attr);
116116
} else {
117117
code.appendLeft(selector.end, attr);
118118
}

src/compiler/compile/css/Stylesheet.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function minify_declarations(
3535
declarations.forEach((declaration, i) => {
3636
const separator = i > 0 ? ';' : '';
3737
if ((declaration.node.start - c) > separator.length) {
38-
code.overwrite(c, declaration.node.start, separator);
38+
code.update(c, declaration.node.start, separator);
3939
}
4040
declaration.minify(code);
4141
c = declaration.node.end;
@@ -75,7 +75,7 @@ class Rule {
7575
if (selector.used) {
7676
const separator = started ? ',' : '';
7777
if ((selector.node.start - c) > separator.length) {
78-
code.overwrite(c, selector.node.start, separator);
78+
code.update(c, selector.node.start, separator);
7979
}
8080

8181
selector.minify(code);
@@ -133,7 +133,7 @@ class Declaration {
133133
if (block.type === 'Identifier') {
134134
const name = block.name;
135135
if (keyframes.has(name)) {
136-
code.overwrite(block.start, block.end, keyframes.get(name));
136+
code.update(block.start, block.end, keyframes.get(name));
137137
}
138138
}
139139
});
@@ -156,7 +156,7 @@ class Declaration {
156156
while (regex_whitespace.test(code.original[start])) start += 1;
157157

158158
if (start - c > 1) {
159-
code.overwrite(c, start, ':');
159+
code.update(c, start, ':');
160160
}
161161
}
162162
}
@@ -204,7 +204,7 @@ class Atrule {
204204
code.remove(c, this.node.block.start);
205205
} else if (this.node.name === 'supports') {
206206
let c = this.node.start + 9;
207-
if (this.node.prelude.start - c > 1) code.overwrite(c, this.node.prelude.start, ' ');
207+
if (this.node.prelude.start - c > 1) code.update(c, this.node.prelude.start, ' ');
208208
this.node.prelude.children.forEach((query: CssNode) => {
209209
// TODO minify queries
210210
c = query.end;
@@ -213,7 +213,7 @@ class Atrule {
213213
} else {
214214
let c = this.node.start + this.node.name.length + 1;
215215
if (this.node.prelude) {
216-
if (this.node.prelude.start - c > 1) code.overwrite(c, this.node.prelude.start, ' ');
216+
if (this.node.prelude.start - c > 1) code.update(c, this.node.prelude.start, ' ');
217217
c = this.node.prelude.end;
218218
}
219219
if (this.node.block && this.node.block.start - c > 0) {
@@ -255,7 +255,7 @@ class Atrule {
255255
});
256256
});
257257
} else {
258-
code.overwrite(start, end, keyframes.get(name));
258+
code.update(start, end, keyframes.get(name));
259259
}
260260
}
261261
});

test/sourcemaps/samples/compile-option-dev/test.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ export async function test({ assert, css, js }) {
1818
// TODO make util fn + move to test index.js
1919
const sourcefile = 'input.svelte';
2020
[
21-
// TODO how to get line + column numbers?
21+
// TODO: get line and col num from input.svelte rather than hardcoding here
2222
[css, '--keep-me', 13, 2],
23-
[css, '--done-replace-once', 6, 5],
24-
[css, '--done-replace-twice', 9, 5]
23+
// TODO: these should be 7, 2 and 10, 2
24+
// we use locate_1 which means lines are 1-indexed and cols are 0-indexed
25+
// each tab is 1 col
26+
[css, '--done-replace-once', 6, 4],
27+
[css, '--done-replace-twice', 9, 4]
2528
]
2629
.forEach(([where, content, line, column]) => {
2730
assert.deepEqual(

0 commit comments

Comments
 (0)