Skip to content
This repository has been archived by the owner on May 16, 2022. It is now read-only.

Commit

Permalink
refactor: a little clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
z0al committed Dec 26, 2020
1 parent 9dd4d74 commit 3b1c9f0
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 365 deletions.
120 changes: 11 additions & 109 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# yarn lockfile v1


"@babel/[email protected]", "@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.4", "@babel/code-frame@^7.5.5", "@babel/code-frame@^7.8.3", "@babel/code-frame@~7.10.4":
"@babel/[email protected]", "@babel/code-frame@~7.10.4":
version "7.10.4"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.10.4.tgz#168da1a36e90da68ae8d49c0f1b48c7c6249213a"
integrity sha512-vG6SvB6oYEhvgisZNFRmRCUkLz11c7rp+tbNTynGqc6mS1d5ATd/sGyV6W0KZZnXRKMTzZDRgQT3Ou9jhpAfUg==
dependencies:
"@babel/highlight" "^7.10.4"

"@babel/code-frame@^7.12.11":
"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.4", "@babel/code-frame@^7.12.11", "@babel/code-frame@^7.5.5", "@babel/code-frame@^7.8.3":
version "7.12.11"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.12.11.tgz#f4ad435aa263db935b8f10f2c552d23fb716a63f"
integrity sha512-Zt1yodBx1UcyiePMSkWnU4hPqhwq7hGi2nFL1LeA3EUl+q2LQx16MISgJ0+z7dnmgvP9QtIleuETGOiOH1RcIw==
Expand Down Expand Up @@ -43,29 +43,7 @@
semver "^5.4.1"
source-map "^0.5.0"

"@babel/core@^7.0.0", "@babel/core@^7.4.5":
version "7.12.9"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.12.9.tgz#fd450c4ec10cdbb980e2928b7aa7a28484593fc8"
integrity sha512-gTXYh3M5wb7FRXQy+FErKFAv90BnlOuNn1QkCK2lREoPAjrQCO49+HVSrFoe5uakFAF5eenS75KbO2vQiLrTMQ==
dependencies:
"@babel/code-frame" "^7.10.4"
"@babel/generator" "^7.12.5"
"@babel/helper-module-transforms" "^7.12.1"
"@babel/helpers" "^7.12.5"
"@babel/parser" "^7.12.7"
"@babel/template" "^7.12.7"
"@babel/traverse" "^7.12.9"
"@babel/types" "^7.12.7"
convert-source-map "^1.7.0"
debug "^4.1.0"
gensync "^1.0.0-beta.1"
json5 "^2.1.2"
lodash "^4.17.19"
resolve "^1.3.2"
semver "^5.4.1"
source-map "^0.5.0"

"@babel/core@~7.12.10":
"@babel/core@^7.0.0", "@babel/core@^7.4.5", "@babel/core@~7.12.10":
version "7.12.10"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.12.10.tgz#b79a2e1b9f70ed3d84bbfb6d8c4ef825f606bccd"
integrity sha512-eTAlQKq65zHfkHZV0sIVODCPGVgoo1HdBlbSLi9CqOzuZanMv2ihzY+4paiKr1mH+XmYESMAmJ/dpZ68eN6d8w==
Expand All @@ -86,7 +64,7 @@
semver "^5.4.1"
source-map "^0.5.0"

"@babel/generator@^7.12.10", "@babel/generator@^7.12.11":
"@babel/generator@^7.12.10", "@babel/generator@^7.12.11", "@babel/generator@^7.5.0", "@babel/generator@^7.9.0":
version "7.12.11"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.12.11.tgz#98a7df7b8c358c9a37ab07a24056853016aba3af"
integrity sha512-Ggg6WPOJtSi8yYQvLVjG8F/TlpWDlKx0OpS4Kt+xMQPs5OaGYWy+v1A+1TvxI6sAMGZpKWWoAQ1DaeQbImlItA==
Expand All @@ -95,15 +73,6 @@
jsesc "^2.5.1"
source-map "^0.5.0"

"@babel/generator@^7.12.5", "@babel/generator@^7.5.0", "@babel/generator@^7.9.0":
version "7.12.5"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.12.5.tgz#a2c50de5c8b6d708ab95be5e6053936c1884a4de"
integrity sha512-m16TQQJ8hPt7E+OS/XVQg/7U184MLXtvuGbCdA7na61vha+ImkyyNM/9DDA0unYCVZn3ZOhng+qz48/KBOT96A==
dependencies:
"@babel/types" "^7.12.5"
jsesc "^2.5.1"
source-map "^0.5.0"

"@babel/helper-annotate-as-pure@^7.10.4":
version "7.10.4"
resolved "https://registry.yarnpkg.com/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.10.4.tgz#5bf0d495a3f757ac3bda48b5bf3b3ba309c72ba3"
Expand Down Expand Up @@ -181,16 +150,7 @@
dependencies:
"@babel/types" "^7.12.1"

"@babel/helper-function-name@^7.10.4":
version "7.10.4"
resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.10.4.tgz#d2d3b20c59ad8c47112fa7d2a94bc09d5ef82f1a"
integrity sha512-YdaSyz1n8gY44EmN7x44zBn9zQ1Ry2Y+3GTA+3vH6Mizke1Vw0aWDM66FOYEPw8//qKkmqOckrGgTYa+6sceqQ==
dependencies:
"@babel/helper-get-function-arity" "^7.10.4"
"@babel/template" "^7.10.4"
"@babel/types" "^7.10.4"

"@babel/helper-function-name@^7.12.11":
"@babel/helper-function-name@^7.10.4", "@babel/helper-function-name@^7.12.11":
version "7.12.11"
resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.12.11.tgz#1fd7738aee5dcf53c3ecff24f1da9c511ec47b42"
integrity sha512-AtQKjtYNolKNi6nNNVLQ27CP6D9oFR6bq/HPYSizlzbp7uC1M59XJe8L+0uXjbIaZaUJF99ruHqVGiKXU/7ybA==
Expand All @@ -199,13 +159,6 @@
"@babel/template" "^7.12.7"
"@babel/types" "^7.12.11"

"@babel/helper-get-function-arity@^7.10.4":
version "7.10.4"
resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.10.4.tgz#98c1cbea0e2332f33f9a4661b8ce1505b2c19ba2"
integrity sha512-EkN3YDB+SRDgiIUnNgcmiD361ti+AVbL3f3Henf6dqqUyr5dMsorno0lJWJuLhDhkI5sYEpgj6y9kB8AOU1I2A==
dependencies:
"@babel/types" "^7.10.4"

"@babel/helper-get-function-arity@^7.12.10":
version "7.12.10"
resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.12.10.tgz#b158817a3165b5faa2047825dfa61970ddcc16cf"
Expand Down Expand Up @@ -294,26 +247,14 @@
dependencies:
"@babel/types" "^7.12.1"

"@babel/helper-split-export-declaration@^7.10.4", "@babel/helper-split-export-declaration@^7.11.0":
version "7.11.0"
resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.11.0.tgz#f8a491244acf6a676158ac42072911ba83ad099f"
integrity sha512-74Vejvp6mHkGE+m+k5vHY93FX2cAtrw1zXrZXRlG4l410Nm9PxfEiVTn1PjDPV5SnmieiueY4AFg2xqhNFuuZg==
dependencies:
"@babel/types" "^7.11.0"

"@babel/helper-split-export-declaration@^7.12.11":
"@babel/helper-split-export-declaration@^7.10.4", "@babel/helper-split-export-declaration@^7.11.0", "@babel/helper-split-export-declaration@^7.12.11":
version "7.12.11"
resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.12.11.tgz#1b4cc424458643c47d37022223da33d76ea4603a"
integrity sha512-LsIVN8j48gHgwzfocYUSkO/hjYAOJqlpJEc7tGXcIm4cubjVUf8LGW6eWRyxEu7gA25q02p0rQUWoCI33HNS5g==
dependencies:
"@babel/types" "^7.12.11"

"@babel/helper-validator-identifier@^7.10.4":
version "7.10.4"
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.10.4.tgz#a78c7a7251e01f616512d31b10adcf52ada5e0d2"
integrity sha512-3U9y+43hz7ZM+rzG24Qe2mufW5KhvFg/NhnNph+i9mgCtdTCtMJuI1TMkrIUiK7Ix4PYlRF9I5dhqaLYA/ADXw==

"@babel/helper-validator-identifier@^7.12.11":
"@babel/helper-validator-identifier@^7.10.4", "@babel/helper-validator-identifier@^7.12.11":
version "7.12.11"
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.12.11.tgz#c9a1f021917dcb5ccf0d4e453e399022981fc9ed"
integrity sha512-np/lG3uARFybkoHokJUmf1QfEvRVCPbmQeUQpKow5cQ3xWrV9i3rUHodKDJPQfTVX61qKi+UdYk8kik84n7XOw==
Expand Down Expand Up @@ -351,12 +292,7 @@
chalk "^2.0.0"
js-tokens "^4.0.0"

"@babel/parser@^7.0.0", "@babel/parser@^7.12.7", "@babel/parser@^7.9.0":
version "7.12.7"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.12.7.tgz#fee7b39fe809d0e73e5b25eecaf5780ef3d73056"
integrity sha512-oWR02Ubp4xTLCAqPRiNIuMVgNO5Aif/xpXtabhzW2HWUD47XJsAB4Zd/Rg30+XeQA3juXigV7hlquOTmwqLiwg==

"@babel/parser@^7.12.10", "@babel/parser@^7.12.11":
"@babel/parser@^7.0.0", "@babel/parser@^7.12.10", "@babel/parser@^7.12.11", "@babel/parser@^7.12.7", "@babel/parser@^7.9.0":
version "7.12.11"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.12.11.tgz#9ce3595bcd74bc5c466905e86c535b8b25011e79"
integrity sha512-N3UxG+uuF4CMYoNj8AhnbAcJF0PiuJ9KHuy1lQmkYsxTer/MAH9UBNHsBoAX/4s6NvlDD047No8mYVGGzLL4hg==
Expand Down Expand Up @@ -1051,22 +987,7 @@
"@babel/parser" "^7.12.7"
"@babel/types" "^7.12.7"

"@babel/traverse@^7.0.0", "@babel/traverse@^7.10.4", "@babel/traverse@^7.12.1", "@babel/traverse@^7.12.5", "@babel/traverse@^7.12.9", "@babel/traverse@^7.9.0":
version "7.12.9"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.12.9.tgz#fad26c972eabbc11350e0b695978de6cc8e8596f"
integrity sha512-iX9ajqnLdoU1s1nHt36JDI9KG4k+vmI8WgjK5d+aDTwQbL2fUnzedNedssA645Ede3PM2ma1n8Q4h2ohwXgMXw==
dependencies:
"@babel/code-frame" "^7.10.4"
"@babel/generator" "^7.12.5"
"@babel/helper-function-name" "^7.10.4"
"@babel/helper-split-export-declaration" "^7.11.0"
"@babel/parser" "^7.12.7"
"@babel/types" "^7.12.7"
debug "^4.1.0"
globals "^11.1.0"
lodash "^4.17.19"

"@babel/traverse@^7.12.10":
"@babel/traverse@^7.0.0", "@babel/traverse@^7.10.4", "@babel/traverse@^7.12.1", "@babel/traverse@^7.12.10", "@babel/traverse@^7.12.5", "@babel/traverse@^7.12.9", "@babel/traverse@^7.9.0":
version "7.12.12"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.12.12.tgz#d0cd87892704edd8da002d674bc811ce64743376"
integrity sha512-s88i0X0lPy45RrLM8b9mz8RPH5FqO9G9p7ti59cToE44xFm1Q+Pjh5Gq4SXBbtb88X7Uy7pexeqRIQDDMNkL0w==
Expand All @@ -1081,16 +1002,7 @@
globals "^11.1.0"
lodash "^4.17.19"

"@babel/types@^7.0.0", "@babel/types@^7.10.4", "@babel/types@^7.10.5", "@babel/types@^7.11.0", "@babel/types@^7.12.1", "@babel/types@^7.12.5", "@babel/types@^7.12.7", "@babel/types@^7.4.4", "@babel/types@^7.9.0":
version "7.12.7"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.12.7.tgz#6039ff1e242640a29452c9ae572162ec9a8f5d13"
integrity sha512-MNyI92qZq6jrQkXvtIiykvl4WtoRrVV9MPn+ZfsoEENjiWcBQ3ZSHrkxnJWgWtLX3XXqX5hrSQ+X69wkmesXuQ==
dependencies:
"@babel/helper-validator-identifier" "^7.10.4"
lodash "^4.17.19"
to-fast-properties "^2.0.0"

"@babel/types@^7.12.10", "@babel/types@^7.12.11", "@babel/types@^7.12.12":
"@babel/types@^7.0.0", "@babel/types@^7.10.4", "@babel/types@^7.10.5", "@babel/types@^7.12.1", "@babel/types@^7.12.10", "@babel/types@^7.12.11", "@babel/types@^7.12.12", "@babel/types@^7.12.5", "@babel/types@^7.12.7", "@babel/types@^7.4.4", "@babel/types@^7.9.0":
version "7.12.12"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.12.12.tgz#4608a6ec313abbd87afa55004d373ad04a96c299"
integrity sha512-lnIX7piTxOH22xE7fDXDbSHg9MM1/6ORnafpJmov5rs0kX5g4BZxeXNJLXsMRiO0U5Rb8/FvMS6xlTnTHvxonQ==
Expand Down Expand Up @@ -3249,17 +3161,7 @@ babel-plugin-dynamic-import-node@^2.3.3:
dependencies:
object.assign "^4.1.0"

babel-plugin-macros@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/babel-plugin-macros/-/babel-plugin-macros-3.0.0.tgz#de9ad21283f8493b2aa70ba0abe82efafb65f5bd"
integrity sha512-KtmdOA0b8gsD8cid2iOdPEPSI45UFkf3wczAWN1FHhfI4UoXMLM6Cdhk72VznDMLPnEC88txqG0101e8MOpsaQ==
dependencies:
"@babel/runtime" "^7.12.5"
"@babel/traverse" "^7.12.9"
cosmiconfig "^7.0.0"
resolve "^1.19.0"

babel-plugin-macros@^3.0.1:
babel-plugin-macros@^3.0.0, babel-plugin-macros@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/babel-plugin-macros/-/babel-plugin-macros-3.0.1.tgz#0d412d68f5b3d1b64358f24ab099bd148724e2a9"
integrity sha512-CKt4+Oy9k2wiN+hT1uZzOw7d8zb1anbQpf7KLwaaXRCi/4pzKdFKHf7v5mvoPmjkmxshh7eKZQuRop06r5WP4w==
Expand Down
2 changes: 1 addition & 1 deletion src/babel/add-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function importModule(
program: NodePath<t.Program>,
exportName: string,
moduleName: string
): t.Identifier {
) {
return importHelpers.addNamed(
program,
exportName,
Expand Down
9 changes: 9 additions & 0 deletions src/babel/generate-uid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as t from '@babel/types';
import { NodePath } from '@babel/core';

export function generateUid(
program: NodePath<t.Program>,
name: string
) {
return program.scope.generateUidIdentifier(name);
}
9 changes: 6 additions & 3 deletions src/macro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Macro } from './lib/types';
import { resolveTokens } from './lib/tokens';
import { evalNode } from './babel/eval-node';
import { importUtil } from './babel/add-import';
import { generateUid } from './babel/generate-uid';
import { injectStyles } from './babel/inject-styles';
import { transformTokens } from './babel/transform-tokens';

Expand All @@ -17,7 +18,7 @@ const styledMacro: MacroHandler = ({ references, state }) => {
const stylesheet: Record<string, Record<string, any>> = {};

// Variable name to be used later with StyleSheet.create
const stylesheetId = program.scope.generateUidIdentifier('styles');
const stylesheetId = generateUid(program, 'styles');

references.default?.forEach((refPath) => {
if (!t.isCallExpression(refPath.parent)) {
Expand Down Expand Up @@ -50,7 +51,7 @@ const styledMacro: MacroHandler = ({ references, state }) => {
resolveTokens(tokens),
stylesheetId,
({ variant, style }) => {
const id = program.scope.generateUidIdentifier(variant);
const id = generateUid(program, variant);
stylesheet[id.name] = style;
return id;
}
Expand Down Expand Up @@ -83,4 +84,6 @@ const styledMacro: MacroHandler = ({ references, state }) => {
}
};

export default createMacro(styledMacro) as Macro;
export default createMacro(styledMacro, {
configName: 'styled',
}) as Macro;
Loading

0 comments on commit 3b1c9f0

Please sign in to comment.