Skip to content
Open
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
9 changes: 6 additions & 3 deletions runtime/createExports.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ module.exports.createExports = function(options) {
create(styles) {
const result = {};
for (const key of Object.keys(styles)) {
result[key] = sheet.process(styles[key], undefined, undefined, options);
const originalClassName =
(options && options.addOriginalClassName) !== false ? `_${key} ` : "";
result[key] =
originalClassName +
sheet.process(styles[key], undefined, undefined, options);
}
browser.insert(sheet.flush());
return result;
Expand All @@ -22,5 +26,4 @@ module.exports.createExports = function(options) {
};

return exports;
}

};
7 changes: 6 additions & 1 deletion src/babel/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ module.exports = function plugin(babel) {
);
const props = [];
for (const key of Object.keys(styles)) {
const originalClassName =
state.opts && state.opts.addOriginalClassName ? `_${key} ` : "";
props.push(
t.objectProperty(
t.identifier(key),
t.stringLiteral(sheet.process(styles[key], undefined, undefined, state.opts))
t.stringLiteral(
originalClassName +
sheet.process(styles[key], undefined, undefined, state.opts)
)
)
);
}
Expand Down
14 changes: 7 additions & 7 deletions tests/babel/__snapshots__/babel.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function getGreen() {
}

const styles = {
bgGreen: \\"gkp15_backgroundColor_green\\"
bgGreen: \\"_bgGreen gkp15_backgroundColor_green\\"
};"
`;

Expand Down Expand Up @@ -94,7 +94,7 @@ const styles = StyleSheet.create({

import * as Colors from \\"./imports/colors.es\\";
const styles = {
bgGreen: \\"gkp15_backgroundColor_green\\"
bgGreen: \\"_bgGreen gkp15_backgroundColor_green\\"
};"
`;

Expand Down Expand Up @@ -149,8 +149,8 @@ const styles = StyleSheet.create({

import { GREEN, RED } from \\"./imports/colors.es\\";
const styles = {
bgGreen: \\"gkp15_backgroundColor_green\\",
bgRed: \\"gkp15_backgroundColor_red\\"
bgGreen: \\"_bgGreen gkp15_backgroundColor_green\\",
bgRed: \\"_bgRed gkp15_backgroundColor_red\\"
};"
`;

Expand Down Expand Up @@ -197,7 +197,7 @@ const styles = StyleSheet.create({
const colors = require(\\"./imports/colors.cjs\\");

const styles = {
bgGreen: \\"gkp15_backgroundColor_green\\"
bgGreen: \\"_bgGreen gkp15_backgroundColor_green\\"
};"
`;

Expand Down Expand Up @@ -240,7 +240,7 @@ const styles = StyleSheet.create({

const green = \\"green\\";
const styles = {
bgGreen: \\"gkp15_backgroundColor_green\\"
bgGreen: \\"_bgGreen gkp15_backgroundColor_green\\"
};"
`;

Expand Down Expand Up @@ -277,6 +277,6 @@ exports[`static.js: prettyCompiled 1`] = `
↓ ↓ ↓ ↓ ↓ ↓

const styles = {
bgGreen: \\"gkp15_backgroundColor_green\\"
bgGreen: \\"_bgGreen gkp15_backgroundColor_green\\"
};"
`;
2 changes: 1 addition & 1 deletion tests/babel/babel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fs.readdirSync(path.resolve(__dirname, "fixtures")).forEach(filename => {
sheet.reset();
const { code: prettyCode } = babel.transform(source, {
filename: realpath,
plugins: [[ plugin, { prettyClassNames: true } ]],
plugins: [[ plugin, { prettyClassNames: true, addOriginalClassName: true } ]],
});
expect(source + separator + prettyCode).toMatchSnapshot("prettyCompiled");
});
Expand Down
10 changes: 7 additions & 3 deletions tests/runtime.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const ReactDOM = require("react-dom");
const ReactTestUtils = require("react-dom/test-utils");

const { StyleSheet, classnames: cn, reset } = require("../runtime");
const { StyleSheet : PrettyStyleSheet } = require("../runtime/pretty");
const { StyleSheet: PrettyStyleSheet } = require("../runtime/pretty");

function childStyle(node, p = null) {
return window.getComputedStyle(node.childNodes[0], p);
Expand Down Expand Up @@ -40,7 +40,9 @@ test("works", () => {
container
);

expect(node.getAttribute("class")).toMatchInlineSnapshot(`"gk0_bf54id"`);
expect(node.getAttribute("class")).toMatchInlineSnapshot(
`"_bgGreen gk0_bf54id"`
);
expect(window.getComputedStyle(node).backgroundColor).toEqual("green");
});

Expand All @@ -56,6 +58,8 @@ test("works [pretty]", () => {
container
);

expect(node.getAttribute("class")).toMatchInlineSnapshot(`"gkp15_backgroundColor_green"`);
expect(node.getAttribute("class")).toMatchInlineSnapshot(
`"_bgGreen gkp15_backgroundColor_green"`
);
expect(window.getComputedStyle(node).backgroundColor).toEqual("green");
});