Skip to content

Commit 5e06ada

Browse files
authored
addFileScope: Don't mangle non-template strings that contain newlines (#1406)
1 parent c239f1f commit 5e06ada

File tree

8 files changed

+73
-24
lines changed

8 files changed

+73
-24
lines changed

.changeset/clean-tigers-drive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@vanilla-extract/integration': patch
3+
---
4+
5+
`addFileScope`: Fixes a bug where non-template strings that contained a newline where being mangled

.changeset/silver-cows-march.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@vanilla-extract/integration': patch
3+
---
4+
5+
Bump `dedent` dependency to `^1.5.3`

packages/css/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
"css-what": "^6.1.0",
113113
"cssesc": "^3.0.0",
114114
"csstype": "^3.0.7",
115-
"dedent": "^1.5.1",
115+
"dedent": "^1.5.3",
116116
"deep-object-diff": "^1.1.9",
117117
"deepmerge": "^4.2.2",
118118
"media-query-parser": "^2.0.2",

packages/integration/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"@babel/plugin-syntax-typescript": "^7.23.3",
1919
"@vanilla-extract/babel-plugin-debug-ids": "^1.0.5",
2020
"@vanilla-extract/css": "^1.15.1",
21-
"dedent": "^1.5.1",
21+
"dedent": "^1.5.3",
2222
"esbuild": "npm:esbuild@~0.17.6 || ~0.18.0 || ~0.19.0",
2323
"eval": "0.1.8",
2424
"find-up": "^5.0.0",

packages/integration/src/addFileScope.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,24 @@ describe('ESM', () => {
147147
vanillaFileScope.endFileScope();
148148
`);
149149
});
150+
151+
test('should preserve non-template strings that contain newline characters', () => {
152+
const source = `export const multiLineString = "\\nfoo\\n";`;
153+
154+
expect(
155+
addFileScope({
156+
source,
157+
rootPath: '/the-root',
158+
filePath: '/the-root/app/app.css.ts',
159+
packageName: 'my-package',
160+
}),
161+
).toMatchInlineSnapshot(`
162+
import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
163+
setFileScope("app/app.css.ts", "my-package");
164+
export const multiLineString = "\\nfoo\\n";
165+
endFileScope();
166+
`);
167+
});
150168
});
151169

152170
describe('CJS', () => {
@@ -266,6 +284,24 @@ describe('CJS', () => {
266284
__vanilla_filescope__.endFileScope();
267285
`);
268286
});
287+
288+
test('should preserve non-template strings that contain newline characters', () => {
289+
const source = `exports.multiLineString = "\\nfoo\\n";`;
290+
291+
expect(
292+
addFileScope({
293+
source,
294+
rootPath: '/the-root',
295+
filePath: '/the-root/app/app.css.ts',
296+
packageName: 'my-package',
297+
}),
298+
).toMatchInlineSnapshot(`
299+
const __vanilla_filescope__ = require("@vanilla-extract/css/fileScope");
300+
__vanilla_filescope__.setFileScope("app/app.css.ts", "my-package");
301+
exports.multiLineString = "\\nfoo\\n";
302+
__vanilla_filescope__.endFileScope();
303+
`);
304+
});
269305
});
270306

271307
test('platform-specific relative path', () => {

packages/integration/src/addFileScope.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ export function addFileScope({
3333
);
3434
} else {
3535
if (hasESM && !isMixed) {
36-
source = dedent`
36+
source = dedent(`
3737
import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
3838
setFileScope("${normalizedPath}", "${packageName}");
3939
${source}
4040
endFileScope();
41-
`;
41+
`);
4242
} else {
43-
source = dedent`
43+
source = dedent(`
4444
const __vanilla_filescope__ = require("@vanilla-extract/css/fileScope");
4545
__vanilla_filescope__.setFileScope("${normalizedPath}", "${packageName}");
4646
${source}
4747
__vanilla_filescope__.endFileScope();
48-
`;
48+
`);
4949
}
5050
}
5151

@@ -55,12 +55,12 @@ export function addFileScope({
5555
? 'import * as __vanilla_css_adapter__ from "@vanilla-extract/css/adapter";'
5656
: 'const __vanilla_css_adapter__ = require("@vanilla-extract/css/adapter");';
5757

58-
source = dedent`
58+
source = dedent(`
5959
${adapterImport}
6060
__vanilla_css_adapter__.setAdapter(${globalAdapterIdentifier});
6161
${source}
6262
__vanilla_css_adapter__.removeAdapter();
63-
`;
63+
`);
6464
}
6565

6666
return source;

pnpm-lock.yaml

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

site/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"@docsearch/react": "3.3.3",
1515
"@mdx-js/react": "^1.6.22",
1616
"classnames": "^2.5.1",
17-
"dedent": "^1.5.1",
17+
"dedent": "^1.5.3",
1818
"lodash": "^4.17.21",
1919
"react": "^18.2.0",
2020
"react-dom": "^18.2.0",

0 commit comments

Comments
 (0)