Skip to content

Commit

Permalink
addFileScope: Don't mangle non-template strings that contain newlin…
Browse files Browse the repository at this point in the history
…es (#1406)
  • Loading branch information
askoufis committed May 4, 2024
1 parent c239f1f commit 5e06ada
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/clean-tigers-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vanilla-extract/integration': patch
---

`addFileScope`: Fixes a bug where non-template strings that contained a newline where being mangled
5 changes: 5 additions & 0 deletions .changeset/silver-cows-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vanilla-extract/integration': patch
---

Bump `dedent` dependency to `^1.5.3`
2 changes: 1 addition & 1 deletion packages/css/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
"css-what": "^6.1.0",
"cssesc": "^3.0.0",
"csstype": "^3.0.7",
"dedent": "^1.5.1",
"dedent": "^1.5.3",
"deep-object-diff": "^1.1.9",
"deepmerge": "^4.2.2",
"media-query-parser": "^2.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@babel/plugin-syntax-typescript": "^7.23.3",
"@vanilla-extract/babel-plugin-debug-ids": "^1.0.5",
"@vanilla-extract/css": "^1.15.1",
"dedent": "^1.5.1",
"dedent": "^1.5.3",
"esbuild": "npm:esbuild@~0.17.6 || ~0.18.0 || ~0.19.0",
"eval": "0.1.8",
"find-up": "^5.0.0",
Expand Down
36 changes: 36 additions & 0 deletions packages/integration/src/addFileScope.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,24 @@ describe('ESM', () => {
vanillaFileScope.endFileScope();
`);
});

test('should preserve non-template strings that contain newline characters', () => {
const source = `export const multiLineString = "\\nfoo\\n";`;

expect(
addFileScope({
source,
rootPath: '/the-root',
filePath: '/the-root/app/app.css.ts',
packageName: 'my-package',
}),
).toMatchInlineSnapshot(`
import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
setFileScope("app/app.css.ts", "my-package");
export const multiLineString = "\\nfoo\\n";
endFileScope();
`);
});
});

describe('CJS', () => {
Expand Down Expand Up @@ -266,6 +284,24 @@ describe('CJS', () => {
__vanilla_filescope__.endFileScope();
`);
});

test('should preserve non-template strings that contain newline characters', () => {
const source = `exports.multiLineString = "\\nfoo\\n";`;

expect(
addFileScope({
source,
rootPath: '/the-root',
filePath: '/the-root/app/app.css.ts',
packageName: 'my-package',
}),
).toMatchInlineSnapshot(`
const __vanilla_filescope__ = require("@vanilla-extract/css/fileScope");
__vanilla_filescope__.setFileScope("app/app.css.ts", "my-package");
exports.multiLineString = "\\nfoo\\n";
__vanilla_filescope__.endFileScope();
`);
});
});

test('platform-specific relative path', () => {
Expand Down
12 changes: 6 additions & 6 deletions packages/integration/src/addFileScope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ export function addFileScope({
);
} else {
if (hasESM && !isMixed) {
source = dedent`
source = dedent(`
import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
setFileScope("${normalizedPath}", "${packageName}");
${source}
endFileScope();
`;
`);
} else {
source = dedent`
source = dedent(`
const __vanilla_filescope__ = require("@vanilla-extract/css/fileScope");
__vanilla_filescope__.setFileScope("${normalizedPath}", "${packageName}");
${source}
__vanilla_filescope__.endFileScope();
`;
`);
}
}

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

source = dedent`
source = dedent(`
${adapterImport}
__vanilla_css_adapter__.setAdapter(${globalAdapterIdentifier});
${source}
__vanilla_css_adapter__.removeAdapter();
`;
`);
}

return source;
Expand Down
33 changes: 18 additions & 15 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@docsearch/react": "3.3.3",
"@mdx-js/react": "^1.6.22",
"classnames": "^2.5.1",
"dedent": "^1.5.1",
"dedent": "^1.5.3",
"lodash": "^4.17.21",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down

0 comments on commit 5e06ada

Please sign in to comment.