1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports["default"] = void 0;
|
5 |
|
6 | var _babelPluginMacros = require("babel-plugin-macros");
|
7 |
|
8 | var _babelExternal = require("./babel-external");
|
9 |
|
10 | var _utils = require("./_utils");
|
11 |
|
12 | var _constants = require("./_constants");
|
13 |
|
14 | var _default = (0, _babelPluginMacros.createMacro)(styledJsxMacro);
|
15 |
|
16 | exports["default"] = _default;
|
17 |
|
18 | function styledJsxMacro(_ref) {
|
19 | var references = _ref.references,
|
20 | state = _ref.state;
|
21 | (0, _utils.setStateOptions)(state);
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | var cssReferences = [];
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | Object.keys(references).forEach(function (refName) {
|
33 |
|
34 |
|
35 |
|
36 | if (refName !== 'default' && refName !== 'resolve') {
|
37 | throw new _babelPluginMacros.MacroError("Imported an invalid named import: " + refName + ". Please import: resolve");
|
38 | }
|
39 |
|
40 |
|
41 | references[refName].forEach(function (path) {
|
42 |
|
43 |
|
44 |
|
45 | var templateExpression = path.parentPath;
|
46 |
|
47 |
|
48 |
|
49 | if (templateExpression.isMemberExpression()) {
|
50 |
|
51 | var tagPropertyName = templateExpression.get('property').node.name;
|
52 |
|
53 |
|
54 | if (refName !== 'default') {
|
55 | throw new _babelPluginMacros.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 }`");
|
56 | }
|
57 |
|
58 |
|
59 | if (tagPropertyName !== 'resolve') {
|
60 | throw new _babelPluginMacros.MacroError("Using an invalid tag: " + tagPropertyName + ". Please use " + templateExpression.get('object').node.name + ".resolve");
|
61 | }
|
62 |
|
63 |
|
64 |
|
65 | templateExpression = templateExpression.parentPath;
|
66 | } else {
|
67 | if (refName === 'default') {
|
68 | var name = path.node.name;
|
69 | throw new _babelPluginMacros.MacroError("Can't use default import directly eg. " + name + "`div { color: red }`. Please use " + name + ".resolve`div { color: red }` instead.");
|
70 | }
|
71 |
|
72 | if (path.node.name === 'css') {
|
73 |
|
74 | cssReferences.push(path.node.loc.start.line);
|
75 | }
|
76 | }
|
77 |
|
78 |
|
79 | (0, _babelExternal.processTaggedTemplateExpression)({
|
80 | type: 'resolve',
|
81 | path: templateExpression,
|
82 | file: state.file,
|
83 | splitRules: typeof state.opts.optimizeForSpeed === 'boolean' ? state.opts.optimizeForSpeed : process.env.NODE_ENV === 'production',
|
84 | plugins: state.plugins,
|
85 | vendorPrefixes: state.opts.vendorPrefixes,
|
86 | sourceMaps: state.opts.sourceMaps
|
87 | });
|
88 |
|
89 | if (!state.hasInjectedJSXStyle && !path.scope.hasBinding(_constants.STYLE_COMPONENT)) {
|
90 | state.hasInjectedJSXStyle = true;
|
91 | (0, _utils.createReactComponentImportDeclaration)(state);
|
92 | }
|
93 | });
|
94 | });
|
95 |
|
96 | if (cssReferences.length > 0) {
|
97 | 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.');
|
98 | }
|
99 | } |
\ | No newline at end of file |