From 9ff019dbc0ccc627934c72bc8adf5dd253b0f7f2 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Mon, 5 Sep 2022 18:53:48 +0200 Subject: [PATCH 1/2] fix: dynamic load babel macro as bundle --- package.json | 8 ++--- src/macro.js | 3 +- yarn.lock | 94 ++++++++-------------------------------------------- 3 files changed, 20 insertions(+), 85 deletions(-) diff --git a/package.json b/package.json index 44970bee..a2d74a3e 100644 --- a/package.json +++ b/package.json @@ -23,9 +23,9 @@ ], "typings": "./index.d.ts", "scripts": { - "build": "rm -rf dist && rm -rf out && yarn build-babel && yarn build-webpack && yarn build-index", - "build-babel": "bunchee src/babel.js -f cjs --runtime node -e react -e babel-plugin-macros -o dist/babel/index.js", - "build-webpack": "bunchee src/webpack.js -f cjs --runtime node -e react -e babel-plugin-macros -o dist/webpack/index.js", + "build-babel": "bunchee src/babel.js -f cjs -e babel-plugin-macros --runtime node -o dist/babel/index.js", + "build": "rm -rf dist && rm -rf out && yarn build-webpack && yarn build-index && yarn build-babel", + "build-webpack": "bunchee src/webpack.js -f cjs --runtime node -o dist/webpack/index.js", "build-index": "bunchee src/index.js -f cjs --runtime node -o dist/index/index.js", "test": "ava", "lint": "eslint ./src", @@ -79,7 +79,7 @@ "@babel/types": "7.15.0", "ava": "4.3.1", "babel-plugin-macros": "2.8.0", - "bunchee": "2.0.3", + "bunchee": "2.0.4", "convert-source-map": "1.7.0", "eslint": "7.32.0", "eslint-config-prettier": "4.0.0", diff --git a/src/macro.js b/src/macro.js index 4f4a3ced..82c3573c 100644 --- a/src/macro.js +++ b/src/macro.js @@ -1,4 +1,3 @@ -import { createMacro, MacroError } from 'babel-plugin-macros' import { processTaggedTemplateExpression } from './babel-external' import { setStateOptions, @@ -6,6 +5,8 @@ import { } from './_utils' import { STYLE_COMPONENT } from './_constants' +const { createMacro, MacroError } = (() => require('babel-plugin-macros'))() + export default createMacro(styledJsxMacro) function styledJsxMacro({ references, state }) { diff --git a/yarn.lock b/yarn.lock index b39c0631..08859e4d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2105,13 +2105,6 @@ brace-expansion@^1.1.7: balanced-match "^1.0.0" concat-map "0.0.1" -brace-expansion@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae" - integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA== - dependencies: - balanced-match "^1.0.0" - braces@^3.0.2, braces@~3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107" @@ -2144,10 +2137,10 @@ builtins@^1.0.3: resolved "https://registry.yarnpkg.com/builtins/-/builtins-1.0.3.tgz#cb94faeb61c8696451db36534e1422f94f0aee88" integrity sha512-uYBjakWipfaO/bXI7E8rq6kpwHRZK5cNYrUv2OzZSI/FvmdMyXJ2tG9dKcjEC5YHmHpUAwsargWIZNWdxb/bnQ== -bunchee@2.0.3: - version "2.0.3" - resolved "https://registry.yarnpkg.com/bunchee/-/bunchee-2.0.3.tgz#09fc2edc6f21041c0d2329111d2de136d08d8276" - integrity sha512-B27ySaWmLBWNl51w/CKa2mQZ36zXFSwgMqYMxbObXTjM5S6wikd6Sqg3kXMOHZmgqMLZUAHJrsVJreTtnozsCw== +bunchee@2.0.4: + version "2.0.4" + resolved "https://registry.yarnpkg.com/bunchee/-/bunchee-2.0.4.tgz#4dfea76194c927a39886daaf1c20c36382ef490a" + integrity sha512-G0E/cteucbJb/2zgR//Xm5awAdHOh6JxRz7zKD6t+lenEefLAPK6x5qj+84bAao6wZ1dDGWLqGWbS3SAAOs6DA== dependencies: "@rollup/plugin-commonjs" "22.0.2" "@rollup/plugin-json" "4.1.0" @@ -2157,7 +2150,7 @@ bunchee@2.0.3: arg "5.0.0" rollup "2.74.1" rollup-plugin-preserve-shebang "1.0.1" - rollup-plugin-swc3 "0.4.1" + rollup-plugin-swc3 "0.5.0" tslib "2.4.0" cacache@^15.0.3, cacache@^15.0.5, cacache@^15.2.0, cacache@^15.3.0: @@ -3371,17 +3364,6 @@ glob@^7.1.1, glob@^7.1.3, glob@^7.1.4, glob@^7.1.6, glob@^7.2.0: once "^1.3.0" path-is-absolute "^1.0.0" -glob@^8.0.3: - version "8.0.3" - resolved "https://registry.yarnpkg.com/glob/-/glob-8.0.3.tgz#415c6eb2deed9e502c68fa44a272e6da6eeca42e" - integrity sha512-ull455NHSHI/Y1FqGaaYFaLGkNMMJbavMrEGFXG/PGrg6y7sutWHUHrz6gy6WEBH6akM1M414dWKCNs+IhKdiQ== - dependencies: - fs.realpath "^1.0.0" - inflight "^1.0.4" - inherits "2" - minimatch "^5.0.1" - once "^1.3.0" - globals@^11.1.0: version "11.12.0" resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e" @@ -3964,10 +3946,10 @@ json5@^2.1.2: resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.1.tgz#655d50ed1e6f95ad1a3caababd2b0efda10b395c" integrity sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA== -jsonc-parser@^3.0.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-3.1.0.tgz#73b8f0e5c940b83d03476bc2e51a20ef0932615d" - integrity sha512-DRf0QjnNeCUds3xTjKlQQ3DpJD51GvDjJfnxUVWg6PZTo2otSm+slzNAxU/35hF8/oJIKoG9slq30JYOsF2azg== +jsonc-parser@^3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-3.2.0.tgz#31ff3f4c2b9793f89c67212627c51c6394f88e76" + integrity sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w== jsonfile@^6.0.1: version "6.1.0" @@ -4249,11 +4231,6 @@ lru-cache@^6.0.0: dependencies: yallist "^4.0.0" -lunr@^2.3.9: - version "2.3.9" - resolved "https://registry.yarnpkg.com/lunr/-/lunr-2.3.9.tgz#18b123142832337dd6e964df1a5a7707b25d35e1" - integrity sha512-zTU3DaZaF3Rt9rhN3uBMGQD3dD2/vFQqnvZCDv4dl5iOzq2IZQqTxu90r4E5J+nP70J3ilqVCrbho2eWaeW8Ow== - magic-string@^0.25.7: version "0.25.9" resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.25.9.tgz#de7f9faf91ef8a1c91d02c2e5314c8277dbcdd1c" @@ -4325,11 +4302,6 @@ marked@^1.0.0: resolved "https://registry.yarnpkg.com/marked/-/marked-1.2.9.tgz#53786f8b05d4c01a2a5a76b7d1ec9943d29d72dc" integrity sha512-H8lIX2SvyitGX+TRdtS06m1jHMijKN/XjfH6Ooii9fvxMlh8QdqBfBDkGUpMWH2kQNrtixjzYUa3SH8ROTgRRw== -marked@^4.0.16: - version "4.0.18" - resolved "https://registry.yarnpkg.com/marked/-/marked-4.0.18.tgz#cd0ac54b2e5610cfb90e8fd46ccaa8292c9ed569" - integrity sha512-wbLDJ7Zh0sqA0Vdg6aqlbT+yPxqLblpAZh1mK2+AO2twQkPywvvqQNfEPVwSSRjZ7dZcdeVBIAgiO7MMp3Dszw== - matcher@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/matcher/-/matcher-5.0.0.tgz#cd82f1c7ae7ee472a9eeaf8ec7cac45e0fe0da62" @@ -4426,13 +4398,6 @@ minimatch@^3.0.4, minimatch@^3.1.1: dependencies: brace-expansion "^1.1.7" -minimatch@^5.0.1, minimatch@^5.1.0: - version "5.1.0" - resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.1.0.tgz#1717b464f4971b144f6aabe8f2d0b8e4511e09c7" - integrity sha512-9TPBGGak4nHfGZsPBohm9AWg6NoT7QTCehS3BIJABslyZbzxfV78QM2Y6+i741OPZIafFAaiiEMh5OyIrJPgtg== - dependencies: - brace-expansion "^2.0.1" - minimist-options@4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/minimist-options/-/minimist-options-4.1.0.tgz#c0655713c53a8a2ebd77ffa247d342c40f010619" @@ -5605,16 +5570,15 @@ rollup-plugin-preserve-shebang@1.0.1: dependencies: magic-string "^0.25.7" -rollup-plugin-swc3@0.4.1: - version "0.4.1" - resolved "https://registry.yarnpkg.com/rollup-plugin-swc3/-/rollup-plugin-swc3-0.4.1.tgz#045dcb21487d072a6327b0beefdc49720f6e2ee0" - integrity sha512-+dB5AJlVjyTTXWgpyhp07vGtv3CLLkvXUS6Y1kABRac7gEpMEfLW70+W0tGyPAeMIs2iQgputMt8eVjNToVfJQ== +rollup-plugin-swc3@0.5.0: + version "0.5.0" + resolved "https://registry.yarnpkg.com/rollup-plugin-swc3/-/rollup-plugin-swc3-0.5.0.tgz#caf745811d1377226ebb41e368eb0a38c70a30c1" + integrity sha512-Y5zJAsvksM39YAmjNje9rWtRMrJefaieDfkv52B2H7PsFj9EuYsrgGJRRUZCiOjMkQwdkiAEYfobqMZFV1X6pg== dependencies: "@rollup/pluginutils" "^4.2.1" deepmerge "^4.2.2" joycon "^3.1.1" - jsonc-parser "^3.0.0" - typedoc "^0.22.15" + jsonc-parser "^3.2.0" rollup@2.74.1: version "2.74.1" @@ -5750,15 +5714,6 @@ shebang-regex@^3.0.0: resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172" integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A== -shiki@^0.10.1: - version "0.10.1" - resolved "https://registry.yarnpkg.com/shiki/-/shiki-0.10.1.tgz#6f9a16205a823b56c072d0f1a0bcd0f2646bef14" - integrity sha512-VsY7QJVzU51j5o1+DguUd+6vmCmZ5v/6gYu4vyYAhzjuNQU6P/vmSy4uQaOhvje031qQMiW0d2BwgMH52vqMng== - dependencies: - jsonc-parser "^3.0.0" - vscode-oniguruma "^1.6.1" - vscode-textmate "5.2.0" - signal-exit@^3.0.0, signal-exit@^3.0.2, signal-exit@^3.0.3, signal-exit@^3.0.7: version "3.0.7" resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9" @@ -6295,17 +6250,6 @@ typedarray-to-buffer@^3.1.5: dependencies: is-typedarray "^1.0.0" -typedoc@^0.22.15: - version "0.22.18" - resolved "https://registry.yarnpkg.com/typedoc/-/typedoc-0.22.18.tgz#1d000c33b66b88fd8cdfea14a26113a83b7e6591" - integrity sha512-NK9RlLhRUGMvc6Rw5USEYgT4DVAUFk7IF7Q6MYfpJ88KnTZP7EneEa4RcP+tX1auAcz7QT1Iy0bUSZBYYHdoyA== - dependencies: - glob "^8.0.3" - lunr "^2.3.9" - marked "^4.0.16" - minimatch "^5.1.0" - shiki "^0.10.1" - uglify-js@^3.1.4: version "3.16.3" resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.16.3.tgz#94c7a63337ee31227a18d03b8a3041c210fd1f1d" @@ -6424,16 +6368,6 @@ verror@1.10.0: core-util-is "1.0.2" extsprintf "^1.2.0" -vscode-oniguruma@^1.6.1: - version "1.6.2" - resolved "https://registry.yarnpkg.com/vscode-oniguruma/-/vscode-oniguruma-1.6.2.tgz#aeb9771a2f1dbfc9083c8a7fdd9cccaa3f386607" - integrity sha512-KH8+KKov5eS/9WhofZR8M8dMHWN2gTxjMsG4jd04YhpbPR91fUj7rYQ2/XjeHCJWbg7X++ApRIU9NUwM2vTvLA== - -vscode-textmate@5.2.0: - version "5.2.0" - resolved "https://registry.yarnpkg.com/vscode-textmate/-/vscode-textmate-5.2.0.tgz#01f01760a391e8222fe4f33fbccbd1ad71aed74e" - integrity sha512-Uw5ooOQxRASHgu6C7GVvUxisKXfSgW4oFlO+aa+PAkgmH89O3CXxEEzNRNtHSqtXFTl0nAC1uYj0GMSH27uwtQ== - walk-up-path@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/walk-up-path/-/walk-up-path-1.0.0.tgz#d4745e893dd5fd0dbb58dd0a4c6a33d9c9fec53e" From b217686c4fa9dbdf06c6e85a2ce9690813951cec Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Mon, 5 Sep 2022 19:42:23 +0200 Subject: [PATCH 2/2] create test macro module --- src/babel.js | 2 +- src/macro.js | 198 ++++++++++++++++--------------- test/fixtures/macro.js | 2 +- test/helpers/babel-test.macro.js | 5 + test/macro.js | 16 +-- 5 files changed, 115 insertions(+), 108 deletions(-) create mode 100644 test/helpers/babel-test.macro.js diff --git a/src/babel.js b/src/babel.js index 7b6e2f3a..bac14c38 100644 --- a/src/babel.js +++ b/src/babel.js @@ -20,7 +20,7 @@ import { default as babelMacro } from './macro' import { default as babelTest } from './babel-test' export function macro() { - return babelMacro + return babelMacro(require('babel-plugin-macros')) } export function test() { diff --git a/src/macro.js b/src/macro.js index 82c3573c..01645a5b 100644 --- a/src/macro.js +++ b/src/macro.js @@ -5,118 +5,120 @@ import { } from './_utils' import { STYLE_COMPONENT } from './_constants' -const { createMacro, MacroError } = (() => require('babel-plugin-macros'))() +export default ({ createMacro, MacroError }) => { + return createMacro(styledJsxMacro) -export default createMacro(styledJsxMacro) + function styledJsxMacro({ references, state }) { + setStateOptions(state) -function styledJsxMacro({ references, state }) { - setStateOptions(state) + // Holds a reference to all the lines where strings are tagged using the `css` tag name. + // We print a warning at the end of the macro in case there is any reference to css, + // because `css` is generally used as default import name for 'styled-jsx/css'. + // People who want to migrate from this macro to pure styled-jsx might have name conflicts issues. + const cssReferences = [] - // Holds a reference to all the lines where strings are tagged using the `css` tag name. - // We print a warning at the end of the macro in case there is any reference to css, - // because `css` is generally used as default import name for 'styled-jsx/css'. - // People who want to migrate from this macro to pure styled-jsx might have name conflicts issues. - const cssReferences = [] + // references looks like this + // { + // default: [path, path], + // resolve: [path], + // } + Object.keys(references).forEach(refName => { + // Enforce `resolve` as named import so people + // can only import { resolve } from 'styled-jsx/macro' + // or an alias of it eg. { resolve as foo } + if (refName !== 'default' && refName !== 'resolve') { + throw new MacroError( + `Imported an invalid named import: ${refName}. Please import: resolve` + ) + } - // references looks like this - // { - // default: [path, path], - // resolve: [path], - // } - Object.keys(references).forEach(refName => { - // Enforce `resolve` as named import so people - // can only import { resolve } from 'styled-jsx/macro' - // or an alias of it eg. { resolve as foo } - if (refName !== 'default' && refName !== 'resolve') { - throw new MacroError( - `Imported an invalid named import: ${refName}. Please import: resolve` - ) - } + // Start processing the references for refName + references[refName].forEach(path => { + // We grab the parent path. Eg. + // path -> css + // path.parenPath -> css`div { color: red }` + let templateExpression = path.parentPath - // Start processing the references for refName - references[refName].forEach(path => { - // We grab the parent path. Eg. - // path -> css - // path.parenPath -> css`div { color: red }` - let templateExpression = path.parentPath + // templateExpression member expression? + // path -> css + // path.parentPath -> css.resolve + if (templateExpression.isMemberExpression()) { + // grab .resolve + const tagPropertyName = templateExpression.get('property').node.name + // Member expressions are only valid on default imports + // eg. import css from 'styled-jsx/macro' + if (refName !== 'default') { + throw new MacroError( + `Can't use named import ${ + path.node.name + } as a member expression: ${ + path.node.name + }.${tagPropertyName}\`div { color: red }\` Please use it directly: ${ + path.node.name + }\`div { color: red }\`` + ) + } - // templateExpression member expression? - // path -> css - // path.parentPath -> css.resolve - if (templateExpression.isMemberExpression()) { - // grab .resolve - const tagPropertyName = templateExpression.get('property').node.name - // Member expressions are only valid on default imports - // eg. import css from 'styled-jsx/macro' - if (refName !== 'default') { - throw new MacroError( - `Can't use named import ${path.node.name} as a member expression: ${ - path.node.name - }.${tagPropertyName}\`div { color: red }\` Please use it directly: ${ - path.node.name - }\`div { color: red }\`` - ) - } + // Otherwise enforce `css.resolve` + if (tagPropertyName !== 'resolve') { + throw new MacroError( + `Using an invalid tag: ${tagPropertyName}. Please use ${ + templateExpression.get('object').node.name + }.resolve` + ) + } - // Otherwise enforce `css.resolve` - if (tagPropertyName !== 'resolve') { - throw new MacroError( - `Using an invalid tag: ${tagPropertyName}. Please use ${ - templateExpression.get('object').node.name - }.resolve` - ) - } + // Grab the TaggedTemplateExpression + // i.e. css.resolve`div { color: red }` + templateExpression = templateExpression.parentPath + } else { + if (refName === 'default') { + const { name } = path.node + throw new MacroError( + `Can't use default import directly eg. ${name}\`div { color: red }\`. Please use ${name}.resolve\`div { color: red }\` instead.` + ) + } - // Grab the TaggedTemplateExpression - // i.e. css.resolve`div { color: red }` - templateExpression = templateExpression.parentPath - } else { - if (refName === 'default') { - const { name } = path.node - throw new MacroError( - `Can't use default import directly eg. ${name}\`div { color: red }\`. Please use ${name}.resolve\`div { color: red }\` instead.` - ) + if (path.node.name === 'css') { + // If the path node name is `css` we push it to the references above to emit a warning later. + cssReferences.push(path.node.loc.start.line) + } } - if (path.node.name === 'css') { - // If the path node name is `css` we push it to the references above to emit a warning later. - cssReferences.push(path.node.loc.start.line) + if (!state.styleComponentImportName) { + const programPath = path.findParent(p => p.isProgram()) + state.styleComponentImportName = programPath.scope.generateUidIdentifier( + STYLE_COMPONENT + ).name + const importDeclaration = createReactComponentImportDeclaration(state) + programPath.unshiftContainer('body', importDeclaration) } - } - - if (!state.styleComponentImportName) { - const programPath = path.findParent(p => p.isProgram()) - state.styleComponentImportName = programPath.scope.generateUidIdentifier( - STYLE_COMPONENT - ).name - const importDeclaration = createReactComponentImportDeclaration(state) - programPath.unshiftContainer('body', importDeclaration) - } - // Finally transform the path :) - processTaggedTemplateExpression({ - type: 'resolve', - path: templateExpression, - file: state.file, - splitRules: - typeof state.opts.optimizeForSpeed === 'boolean' - ? state.opts.optimizeForSpeed - : process.env.NODE_ENV === 'production', - plugins: state.plugins, - vendorPrefixes: state.opts.vendorPrefixes, - sourceMaps: state.opts.sourceMaps, - styleComponentImportName: state.styleComponentImportName + // Finally transform the path :) + processTaggedTemplateExpression({ + type: 'resolve', + path: templateExpression, + file: state.file, + splitRules: + typeof state.opts.optimizeForSpeed === 'boolean' + ? state.opts.optimizeForSpeed + : process.env.NODE_ENV === 'production', + plugins: state.plugins, + vendorPrefixes: state.opts.vendorPrefixes, + sourceMaps: state.opts.sourceMaps, + styleComponentImportName: state.styleComponentImportName + }) }) }) - }) - if (cssReferences.length > 0) { - console.warn( - `styled-jsx - Warning - We detected that you named your tag as \`css\` at lines: ${cssReferences.join( - ', ' - )}.\n` + - 'This tag name is usually used as default import name for `styled-jsx/css`.\n' + - 'Porting macro code to pure styled-jsx in the future might be a bit problematic.' - ) + if (cssReferences.length > 0) { + console.warn( + `styled-jsx - Warning - We detected that you named your tag as \`css\` at lines: ${cssReferences.join( + ', ' + )}.\n` + + 'This tag name is usually used as default import name for `styled-jsx/css`.\n' + + 'Porting macro code to pure styled-jsx in the future might be a bit problematic.' + ) + } } } diff --git a/test/fixtures/macro.js b/test/fixtures/macro.js index 38e0a35a..0ad1b320 100644 --- a/test/fixtures/macro.js +++ b/test/fixtures/macro.js @@ -1,4 +1,4 @@ -import css, { resolve } from '../../src/macro' +import css, { resolve } from '../../test/helpers/babel-test.macro' const { className, styles } = resolve` div { color: red } diff --git a/test/helpers/babel-test.macro.js b/test/helpers/babel-test.macro.js new file mode 100644 index 00000000..86a12b20 --- /dev/null +++ b/test/helpers/babel-test.macro.js @@ -0,0 +1,5 @@ +import { macro } from '../../src/babel' + +const m = macro() +console.log('m', m) +export default m diff --git a/test/macro.js b/test/macro.js index 93848fc4..f8d5ce2e 100644 --- a/test/macro.js +++ b/test/macro.js @@ -27,7 +27,7 @@ test('transpiles correctly', async t => { test('throws when using the default export directly', async t => { const { message } = await t.throwsAsync(() => transformSource(` - import css from './src/macro' + import css from './test/helpers/babel-test.macro' css\`div { color: red }\` `) @@ -39,7 +39,7 @@ test('throws when using the default export directly', async t => { test('throws when using the default export directly and it is not called css', async t => { const { message } = await t.throwsAsync(() => transformSource(` - import foo from './src/macro' + import foo from './test/helpers/babel-test.macro' foo\`div { color: red }\` `) @@ -51,7 +51,7 @@ test('throws when using the default export directly and it is not called css', a test('throws when using the default export directly and it is not called resolve', async t => { const { message } = await t.throwsAsync(() => transformSource(` - import resolve from './src/macro' + import resolve from './test/helpers/babel-test.macro' resolve\`div { color: red }\` `) @@ -63,7 +63,7 @@ test('throws when using the default export directly and it is not called resolve test('throws when using an invalid method from the default export', async t => { const { message } = await t.throwsAsync(() => transformSource(` - import css from './src/macro' + import css from './test/helpers/babel-test.macro' css.foo\`div { color: red }\` `) @@ -75,7 +75,7 @@ test('throws when using an invalid method from the default export', async t => { test('throws when using a named import different than resolve', async t => { const { message } = await t.throwsAsync(() => transformSource(` - import { foo } from './src/macro' + import { foo } from './test/helpers/babel-test.macro' foo\`div { color: red }\` `) @@ -87,7 +87,7 @@ test('throws when using a named import different than resolve', async t => { test('throws when using a named import as a member expression', async t => { const { message } = await t.throwsAsync(() => transformSource(` - import { resolve } from './src/macro' + import { resolve } from './test/helpers/babel-test.macro' resolve.foo\`div { color: red }\` `) @@ -98,7 +98,7 @@ test('throws when using a named import as a member expression', async t => { test('can alias the named import', async t => { const { code } = await transformSource(` - import { resolve as foo } from './src/macro' + import { resolve as foo } from './test/helpers/babel-test.macro' foo\`div { color: red }\` `) @@ -107,7 +107,7 @@ test('can alias the named import', async t => { test('injects JSXStyle for nested scope', async t => { const { code } = await transformSource(` - import { resolve } from './src/macro' + import { resolve } from './test/helpers/babel-test.macro' function test() { resolve\`div { color: red }\`