chore: upgrade magic-string (#8339)

- overwrite -> update
- update comments
pull/8349/head
Ben McCann 3 years ago committed by GitHub
parent 0966d1d282
commit 5b2fa1f247
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

21
package-lock.json generated

@ -38,7 +38,7 @@
"jsdom": "^15.2.1", "jsdom": "^15.2.1",
"kleur": "^4.1.5", "kleur": "^4.1.5",
"locate-character": "^2.0.5", "locate-character": "^2.0.5",
"magic-string": "^0.25.3", "magic-string": "^0.30.0",
"mocha": "^7.0.0", "mocha": "^7.0.0",
"periscopic": "^3.0.4", "periscopic": "^3.0.4",
"puppeteer": "^2.0.0", "puppeteer": "^2.0.0",
@ -3532,12 +3532,15 @@
} }
}, },
"node_modules/magic-string": { "node_modules/magic-string": {
"version": "0.25.3", "version": "0.30.0",
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.3.tgz", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.0.tgz",
"integrity": "sha512-6QK0OpF/phMz0Q2AxILkX2mFhi7m+WMwTRg0LQKq/WBB0cDP4rYH3Wp4/d3OTXlrPLVJT/RFqj8tFeAR4nk8AA==", "integrity": "sha512-LA+31JYDJLs82r2ScLrlz1GjSgu66ZV518eyWT+S8VhyQn/JL0u9MeBOvQMGYiPk1DBiSN9DDMOcXvigJZaViQ==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"sourcemap-codec": "^1.4.4" "@jridgewell/sourcemap-codec": "^1.4.13"
},
"engines": {
"node": ">=12"
} }
}, },
"node_modules/mdn-data": { "node_modules/mdn-data": {
@ -7961,12 +7964,12 @@
} }
}, },
"magic-string": { "magic-string": {
"version": "0.25.3", "version": "0.30.0",
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.3.tgz", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.0.tgz",
"integrity": "sha512-6QK0OpF/phMz0Q2AxILkX2mFhi7m+WMwTRg0LQKq/WBB0cDP4rYH3Wp4/d3OTXlrPLVJT/RFqj8tFeAR4nk8AA==", "integrity": "sha512-LA+31JYDJLs82r2ScLrlz1GjSgu66ZV518eyWT+S8VhyQn/JL0u9MeBOvQMGYiPk1DBiSN9DDMOcXvigJZaViQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"sourcemap-codec": "^1.4.4" "@jridgewell/sourcemap-codec": "^1.4.13"
} }
}, },
"mdn-data": { "mdn-data": {

@ -148,7 +148,7 @@
"jsdom": "^15.2.1", "jsdom": "^15.2.1",
"kleur": "^4.1.5", "kleur": "^4.1.5",
"locate-character": "^2.0.5", "locate-character": "^2.0.5",
"magic-string": "^0.25.3", "magic-string": "^0.30.0",
"mocha": "^7.0.0", "mocha": "^7.0.0",
"periscopic": "^3.0.4", "periscopic": "^3.0.4",
"puppeteer": "^2.0.0", "puppeteer": "^2.0.0",

@ -76,7 +76,7 @@ export default class Selector {
this.blocks.forEach((block, i) => { this.blocks.forEach((block, i) => {
if (i > 0) { if (i > 0) {
if (block.start - c > 1) { if (block.start - c > 1) {
code.overwrite(c, block.start, block.combinator.name || ' '); code.update(c, block.start, block.combinator.name || ' ');
} }
} }
@ -112,7 +112,7 @@ export default class Selector {
} }
if (selector.type === 'TypeSelector' && selector.name === '*') { if (selector.type === 'TypeSelector' && selector.name === '*') {
code.overwrite(selector.start, selector.end, attr); code.update(selector.start, selector.end, attr);
} else { } else {
code.appendLeft(selector.end, attr); code.appendLeft(selector.end, attr);
} }

@ -35,7 +35,7 @@ function minify_declarations(
declarations.forEach((declaration, i) => { declarations.forEach((declaration, i) => {
const separator = i > 0 ? ';' : ''; const separator = i > 0 ? ';' : '';
if ((declaration.node.start - c) > separator.length) { if ((declaration.node.start - c) > separator.length) {
code.overwrite(c, declaration.node.start, separator); code.update(c, declaration.node.start, separator);
} }
declaration.minify(code); declaration.minify(code);
c = declaration.node.end; c = declaration.node.end;
@ -75,7 +75,7 @@ class Rule {
if (selector.used) { if (selector.used) {
const separator = started ? ',' : ''; const separator = started ? ',' : '';
if ((selector.node.start - c) > separator.length) { if ((selector.node.start - c) > separator.length) {
code.overwrite(c, selector.node.start, separator); code.update(c, selector.node.start, separator);
} }
selector.minify(code); selector.minify(code);
@ -133,7 +133,7 @@ class Declaration {
if (block.type === 'Identifier') { if (block.type === 'Identifier') {
const name = block.name; const name = block.name;
if (keyframes.has(name)) { if (keyframes.has(name)) {
code.overwrite(block.start, block.end, keyframes.get(name)); code.update(block.start, block.end, keyframes.get(name));
} }
} }
}); });
@ -156,7 +156,7 @@ class Declaration {
while (regex_whitespace.test(code.original[start])) start += 1; while (regex_whitespace.test(code.original[start])) start += 1;
if (start - c > 1) { if (start - c > 1) {
code.overwrite(c, start, ':'); code.update(c, start, ':');
} }
} }
} }
@ -204,7 +204,7 @@ class Atrule {
code.remove(c, this.node.block.start); code.remove(c, this.node.block.start);
} else if (this.node.name === 'supports') { } else if (this.node.name === 'supports') {
let c = this.node.start + 9; 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) => { this.node.prelude.children.forEach((query: CssNode) => {
// TODO minify queries // TODO minify queries
c = query.end; c = query.end;
@ -213,7 +213,7 @@ class Atrule {
} else { } else {
let c = this.node.start + this.node.name.length + 1; let c = this.node.start + this.node.name.length + 1;
if (this.node.prelude) { 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; c = this.node.prelude.end;
} }
if (this.node.block && this.node.block.start - c > 0) { if (this.node.block && this.node.block.start - c > 0) {
@ -255,7 +255,7 @@ class Atrule {
}); });
}); });
} else { } else {
code.overwrite(start, end, keyframes.get(name)); code.update(start, end, keyframes.get(name));
} }
} }
}); });

@ -18,10 +18,13 @@ export async function test({ assert, css, js }) {
// TODO make util fn + move to test index.js // TODO make util fn + move to test index.js
const sourcefile = 'input.svelte'; 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, '--keep-me', 13, 2],
[css, '--done-replace-once', 6, 5], // TODO: these should be 7, 2 and 10, 2
[css, '--done-replace-twice', 9, 5] // 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]) => { .forEach(([where, content, line, column]) => {
assert.deepEqual( assert.deepEqual(

Loading…
Cancel
Save