Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.js
node_modules
/node_modules/
/lib/**/*.js
index.js
6 changes: 6 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
presets: [
['@babel/preset-env', {targets: {node: 'current'}}],
'@babel/preset-typescript',
]
};
94 changes: 47 additions & 47 deletions lib/__tests__/convertCssForEmotion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,53 +115,6 @@ select.form-control:not([size]):not([multiple]) {

const cssForEmotion = `import { css, injectGlobal } from "emotion";

injectGlobal\`*, *::before, *::after {
box-sizing: inherit;
}



@-ms-viewport {
width: device-width;
}




































\`;

export const close = css\`
float: right;
font-size: 1.5rem;
Expand Down Expand Up @@ -281,6 +234,53 @@ export const formControl = css\`select&:not([size]):not([multiple]) {
color: #868e96;
opacity: 1;
}

\`;

injectGlobal\`*, *::before, *::after {
box-sizing: inherit;
}



@-ms-viewport {
width: device-width;
}




































\`;
`;
Expand Down
2 changes: 1 addition & 1 deletion lib/convertCssForEmotion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function convertCssForEmotion(css: string): string {

return collator.compare(scopeA, scopeB);
})
.reduce((previousSortedKnownScopes: Set<string>, knownScope) => {
.reduce((previousSortedKnownScopes: Set<string>, knownScope: string) => {
getRequiredScopes(
cssIndexedByScope.get(knownScope) as string,
knownScope,
Expand Down
2 changes: 1 addition & 1 deletion lib/convertScopeToModuleName.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as camelCase from "camelcase";
import camelCase from "camelcase";

export function convertScopeToModuleName(scope: string) {
return camelCase(scope)
Expand Down
11 changes: 6 additions & 5 deletions lib/convertScopedCssForEmotion.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as postcss from "postcss";
import * as Stringifier from "postcss/lib/stringifier";
import {parse} from "postcss";
import type {Node} from "postcss";
import Stringifier from "postcss/lib/stringifier";

import { convertSelectorForEmotion } from "./convertSelectorForEmotion";
import { escapeScopedCss } from "./escapeScopedCss";
Expand All @@ -13,7 +14,7 @@ export function convertScopedCssForEmotion(

function builder(
output: string,
node?: postcss.Node,
node?: Node,
flag?: "start" | "end",
) {
if (
Expand Down Expand Up @@ -50,8 +51,8 @@ export function convertScopedCssForEmotion(
scopedCssForEmotion += output;
}

(new Stringifier(builder) as postcss.Stringifier).stringify(
postcss.parse(scopedCss),
(new Stringifier(builder)).stringify(
parse(scopedCss),
);

return escapeScopedCss(scopedCssForEmotion);
Expand Down
2 changes: 1 addition & 1 deletion lib/convertSelectorForEmotion.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as parseSelector from "postcss-selector-parser";
import parseSelector from "postcss-selector-parser";

import { convertScopeToModuleName } from "./convertScopeToModuleName";

Expand Down
11 changes: 6 additions & 5 deletions lib/getCssIndexedByScope.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as postcss from "postcss";
import * as Stringifier from "postcss/lib/stringifier";
import {parse} from "postcss";
import type {Node} from "postcss";
import Stringifier from "postcss/lib/stringifier";

import { getNodeScopes } from "./getNodeScopes";
import { getSelectorScope } from "./getSelectorScope";
Expand All @@ -11,7 +12,7 @@ export function getCssIndexedByScope(css: string): Map<string, string> {

function builder(
output: string,
node?: postcss.Node,
node?: Node,
flag?: "start" | "end",
) {
if (flag === "start" && node) {
Expand Down Expand Up @@ -48,8 +49,8 @@ export function getCssIndexedByScope(css: string): Map<string, string> {
}
}

(new Stringifier(builder) as postcss.Stringifier).stringify(
postcss.parse(css),
(new Stringifier(builder)).stringify(
parse(css),
);

return cssIndexedByScope;
Expand Down
6 changes: 3 additions & 3 deletions lib/getNodeScopes.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as postcss from "postcss";
import type {Node} from "postcss";

import { getSelectorScope } from "./getSelectorScope";

export function getNodeScopes(node: postcss.Node): Set<string> {
const nodeScopes = new Set();
export function getNodeScopes(node: Node): Set<string> {
const nodeScopes: Set<string> = new Set();

if (
node.type === "rule" &&
Expand Down
8 changes: 4 additions & 4 deletions lib/getRequiredScopes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as postcss from "postcss";
import * as parseSelector from "postcss-selector-parser";
import {parse} from "postcss";
import parseSelector from "postcss-selector-parser";

import { getSelectorScope } from "./getSelectorScope";

Expand All @@ -8,9 +8,9 @@ export function getRequiredScopes(
scope: string,
knownScopes: Set<string>,
): Set<string> {
const requiredScopes = new Set();
const requiredScopes: Set<string> = new Set();

const root = postcss.parse(css);
const root = parse(css);
root.walkRules((rule) => {
parseSelector((nodes: any) => {
nodes.walkClasses((node: any) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/getSelectorScope.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as parseSelector from "postcss-selector-parser";
import parseSelector from "postcss-selector-parser";

export function getSelectorScope(selector: string): string {
let selectorScope = "root";
Expand Down
Loading