styled-components 6.0.0-beta.1 → 6.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constructors/constructWithOptions.d.ts +26 -30
- package/dist/constructors/createGlobalStyle.d.ts +2 -2
- package/dist/constructors/css.d.ts +2 -2
- package/dist/constructors/keyframes.d.ts +1 -1
- package/dist/constructors/styled.d.ts +177 -181
- package/dist/hoc/withTheme.d.ts +2 -2
- package/dist/models/GlobalStyle.d.ts +1 -1
- package/dist/models/InlineStyle.d.ts +1 -1
- package/dist/models/StyledComponent.d.ts +1 -1
- package/dist/models/StyledNativeComponent.d.ts +2 -2
- package/dist/native/index.d.ts +27 -31
- package/dist/styled-components-macro.cjs.js +47 -1
- package/dist/styled-components-macro.cjs.js.map +1 -1
- package/dist/styled-components-macro.esm.js +38 -1
- package/dist/styled-components-macro.esm.js.map +1 -1
- package/dist/styled-components.browser.cjs.js +1848 -1
- package/dist/styled-components.browser.cjs.js.map +1 -1
- package/dist/styled-components.browser.esm.js +1823 -1
- package/dist/styled-components.browser.esm.js.map +1 -1
- package/dist/styled-components.cjs.js +1868 -1
- package/dist/styled-components.cjs.js.map +1 -1
- package/dist/styled-components.esm.js +1843 -1
- package/dist/styled-components.esm.js.map +1 -1
- package/dist/styled-components.js +2068 -1
- package/dist/styled-components.js.map +1 -1
- package/dist/styled-components.min.js +1 -1
- package/dist/styled-components.min.js.map +1 -1
- package/dist/test/utils.d.ts +176 -180
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +63 -68
- package/dist/utils/determineTheme.d.ts +2 -2
- package/dist/utils/empties.d.ts +2 -2
- package/dist/utils/flatten.d.ts +3 -3
- package/dist/utils/generateDisplayName.d.ts +1 -1
- package/dist/utils/getComponentName.d.ts +1 -1
- package/dist/utils/interleave.d.ts +1 -1
- package/dist/utils/isStaticRules.d.ts +1 -1
- package/dist/utils/isStyledComponent.d.ts +1 -1
- package/dist/utils/isTag.d.ts +1 -1
- package/dist/utils/mixinDeep.d.ts +2 -2
- package/native/dist/constructors/constructWithOptions.d.ts +26 -30
- package/native/dist/constructors/createGlobalStyle.d.ts +2 -2
- package/native/dist/constructors/css.d.ts +2 -2
- package/native/dist/constructors/keyframes.d.ts +1 -1
- package/native/dist/constructors/styled.d.ts +177 -181
- package/native/dist/hoc/withTheme.d.ts +2 -2
- package/native/dist/models/GlobalStyle.d.ts +1 -1
- package/native/dist/models/InlineStyle.d.ts +1 -1
- package/native/dist/models/StyledComponent.d.ts +1 -1
- package/native/dist/models/StyledNativeComponent.d.ts +2 -2
- package/native/dist/native/index.d.ts +27 -31
- package/native/dist/styled-components.native.cjs.js +15 -26
- package/native/dist/styled-components.native.cjs.js.map +1 -1
- package/native/dist/styled-components.native.esm.js +15 -26
- package/native/dist/styled-components.native.esm.js.map +1 -1
- package/native/dist/test/utils.d.ts +176 -180
- package/native/dist/types.d.ts +63 -68
- package/native/dist/utils/determineTheme.d.ts +2 -2
- package/native/dist/utils/empties.d.ts +2 -2
- package/native/dist/utils/flatten.d.ts +3 -3
- package/native/dist/utils/generateDisplayName.d.ts +1 -1
- package/native/dist/utils/getComponentName.d.ts +1 -1
- package/native/dist/utils/interleave.d.ts +1 -1
- package/native/dist/utils/isStaticRules.d.ts +1 -1
- package/native/dist/utils/isStyledComponent.d.ts +1 -1
- package/native/dist/utils/isTag.d.ts +1 -1
- package/native/dist/utils/mixinDeep.d.ts +2 -2
- package/package.json +2 -3
package/dist/hoc/withTheme.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { AnyComponent,
|
|
3
|
-
export default function withTheme<T extends AnyComponent>(Component: T): React.ForwardRefExoticComponent<React.PropsWithoutRef<JSX.LibraryManagedAttributes<T,
|
|
2
|
+
import { AnyComponent, ExecutionProps } from '../types';
|
|
3
|
+
export default function withTheme<T extends AnyComponent>(Component: T): React.ForwardRefExoticComponent<React.PropsWithoutRef<JSX.LibraryManagedAttributes<T, ExecutionProps>> & React.RefAttributes<T>> & { [key in Exclude<keyof T, T extends React.MemoExoticComponent<any> ? "propTypes" | "defaultProps" | "displayName" | "$$typeof" | "type" | "compare" : T extends React.ForwardRefExoticComponent<any> ? "propTypes" | "defaultProps" | "displayName" | "$$typeof" | "render" : "length" | "propTypes" | "contextType" | "contextTypes" | "childContextTypes" | "defaultProps" | "displayName" | "getDerivedStateFromProps" | "getDerivedStateFromError" | "type" | "getDefaultProps" | "mixins" | "name" | "prototype" | "caller" | "callee" | "arguments" | "arity">]: T[key]; };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import StyleSheet from '../sheet';
|
|
2
2
|
import { ExecutionContext, FlattenerResult, RuleSet, Stringifier } from '../types';
|
|
3
|
-
export default class GlobalStyle<Props
|
|
3
|
+
export default class GlobalStyle<Props extends object> {
|
|
4
4
|
componentId: string;
|
|
5
5
|
isStatic: boolean;
|
|
6
6
|
rules: FlattenerResult<Props>;
|
|
@@ -3,4 +3,4 @@ export declare const resetStyleCache: () => void;
|
|
|
3
3
|
/**
|
|
4
4
|
* InlineStyle takes arbitrary CSS and generates a flat object
|
|
5
5
|
*/
|
|
6
|
-
export default function makeInlineStyleClass<Props
|
|
6
|
+
export default function makeInlineStyleClass<Props extends object>(styleSheet: StyleSheet): IInlineStyleConstructor<Props>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { IStyledComponentFactory, RuleSet, StyledOptions, WebTarget } from '../types';
|
|
2
|
-
declare function createStyledComponent<Target extends WebTarget, OuterProps
|
|
2
|
+
declare function createStyledComponent<Target extends WebTarget, OuterProps extends object, Statics extends object = object>(target: Target, options: StyledOptions<'web', OuterProps>, rules: RuleSet<OuterProps>): ReturnType<IStyledComponentFactory<'web', Target, OuterProps, Statics>>;
|
|
3
3
|
export default createStyledComponent;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
declare const _default: (InlineStyle: IInlineStyleConstructor<any>) => <Target extends NativeTarget, OuterProps extends
|
|
1
|
+
import type { ExecutionProps, IInlineStyleConstructor, IStyledComponent, IStyledComponentFactory, NativeTarget, RuleSet, StyledOptions } from '../types';
|
|
2
|
+
declare const _default: (InlineStyle: IInlineStyleConstructor<any>) => <Target extends NativeTarget, OuterProps extends ExecutionProps, Statics extends object = object>(target: Target, options: StyledOptions<"native", OuterProps>, rules: RuleSet<OuterProps>) => IStyledComponent<"native", Target, OuterProps & object> & Statics & object;
|
|
3
3
|
export default _default;
|
package/dist/native/index.d.ts
CHANGED
|
@@ -1,41 +1,37 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Styled } from '../constructors/constructWithOptions';
|
|
3
3
|
import css from '../constructors/css';
|
|
4
4
|
import withTheme from '../hoc/withTheme';
|
|
5
5
|
import useTheme from '../hooks/useTheme';
|
|
6
6
|
import ThemeProvider, { ThemeConsumer, ThemeContext } from '../models/ThemeProvider';
|
|
7
7
|
import { NativeTarget } from '../types';
|
|
8
8
|
import isStyledComponent from '../utils/isStyledComponent';
|
|
9
|
-
declare const styled: (<Target extends NativeTarget>(tag: Target) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
TouchableHighlight: NativeStyled<typeof import("react-native").TouchableHighlight, import("react-native").TouchableHighlightProps, unknown, unknown>;
|
|
35
|
-
TouchableOpacity: NativeStyled<typeof import("react-native").TouchableOpacity, import("react-native").TouchableOpacityProps, unknown, unknown>;
|
|
36
|
-
View: NativeStyled<typeof import("react-native").View, import("react-native").ViewProps, unknown, unknown>;
|
|
37
|
-
VirtualizedList: NativeStyled<typeof import("react-native").VirtualizedList, import("react-native").VirtualizedListProps<unknown>, unknown, unknown>;
|
|
9
|
+
declare const styled: (<Target extends NativeTarget>(tag: Target) => Styled<"native", Target, Target extends import("../types").KnownTarget ? React.ComponentPropsWithRef<Target> : object, object>) & {
|
|
10
|
+
ActivityIndicator: Styled<"native", typeof import("react-native").ActivityIndicator, import("react-native").ActivityIndicatorProps & React.RefAttributes<import("react-native").ActivityIndicator>, object>;
|
|
11
|
+
Button: Styled<"native", typeof import("react-native").Button, import("react-native").ButtonProps & React.RefAttributes<import("react-native").Button>, object>;
|
|
12
|
+
DatePickerIOS: Styled<"native", typeof import("react-native").DatePickerIOS, import("react-native").DatePickerIOSProps & React.RefAttributes<import("react-native").DatePickerIOS>, object>;
|
|
13
|
+
DrawerLayoutAndroid: Styled<"native", typeof import("react-native").DrawerLayoutAndroid, import("react-native").DrawerLayoutAndroidProps & React.RefAttributes<import("react-native").DrawerLayoutAndroid>, object>;
|
|
14
|
+
FlatList: Styled<"native", typeof import("react-native").FlatList, import("react-native").FlatListProps<unknown> & React.RefAttributes<import("react-native").FlatList<unknown>>, object>;
|
|
15
|
+
Image: Styled<"native", typeof import("react-native").Image, import("react-native").ImageProps & React.RefAttributes<import("react-native").Image>, object>;
|
|
16
|
+
ImageBackground: Styled<"native", typeof import("react-native").ImageBackground, import("react-native").ImageBackgroundProps & React.RefAttributes<import("react-native").ImageBackground>, object>;
|
|
17
|
+
KeyboardAvoidingView: Styled<"native", typeof import("react-native").KeyboardAvoidingView, import("react-native").KeyboardAvoidingViewProps & React.RefAttributes<import("react-native").KeyboardAvoidingView>, object>;
|
|
18
|
+
Modal: Styled<"native", typeof import("react-native").Modal, import("react-native").ModalBaseProps & import("react-native").ModalPropsIOS & import("react-native").ModalPropsAndroid & import("react-native").ViewProps & React.RefAttributes<import("react-native").Modal>, object>;
|
|
19
|
+
Pressable: Styled<"native", import("react").ForwardRefExoticComponent<import("react-native").PressableProps & import("react").RefAttributes<import("react-native").View>>, import("react-native").PressableProps & import("react").RefAttributes<import("react-native").View>, object>;
|
|
20
|
+
ProgressBarAndroid: Styled<"native", typeof import("react-native").ProgressBarAndroid, import("react-native").ProgressBarAndroidProps & React.RefAttributes<import("react-native").ProgressBarAndroid>, object>;
|
|
21
|
+
ProgressViewIOS: Styled<"native", typeof import("react-native").ProgressViewIOS, import("react-native").ProgressViewIOSProps & React.RefAttributes<import("react-native").ProgressViewIOS>, object>;
|
|
22
|
+
RefreshControl: Styled<"native", typeof import("react-native").RefreshControl, import("react-native").RefreshControlProps & React.RefAttributes<import("react-native").RefreshControl>, object>;
|
|
23
|
+
SafeAreaView: Styled<"native", typeof import("react-native").SafeAreaView, import("react-native").ViewProps & React.RefAttributes<import("react-native").SafeAreaView>, object>;
|
|
24
|
+
ScrollView: Styled<"native", typeof import("react-native").ScrollView, import("react-native").ScrollViewProps & React.RefAttributes<import("react-native").ScrollView>, object>;
|
|
25
|
+
SectionList: Styled<"native", typeof import("react-native").SectionList, import("react-native").SectionListProps<unknown, unknown> & React.RefAttributes<import("react-native").SectionList<unknown, unknown>>, object>;
|
|
26
|
+
Slider: Styled<"native", typeof import("react-native").Slider, import("react-native").SliderProps & React.RefAttributes<import("react-native").Slider>, object>;
|
|
27
|
+
Switch: Styled<"native", typeof import("react-native").Switch, import("react-native").SwitchProps & React.RefAttributes<import("react-native").Switch>, object>;
|
|
28
|
+
Text: Styled<"native", typeof import("react-native").Text, import("react-native").TextProps & React.RefAttributes<import("react-native").Text>, object>;
|
|
29
|
+
TextInput: Styled<"native", typeof import("react-native").TextInput, import("react-native").TextInputProps & React.RefAttributes<import("react-native").TextInput>, object>;
|
|
30
|
+
TouchableHighlight: Styled<"native", typeof import("react-native").TouchableHighlight, import("react-native").TouchableHighlightProps & React.RefAttributes<import("react-native").TouchableHighlight>, object>;
|
|
31
|
+
TouchableOpacity: Styled<"native", typeof import("react-native").TouchableOpacity, import("react-native").TouchableOpacityProps & React.RefAttributes<import("react-native").TouchableOpacity>, object>;
|
|
32
|
+
View: Styled<"native", typeof import("react-native").View, import("react-native").ViewProps & React.RefAttributes<import("react-native").View>, object>;
|
|
33
|
+
VirtualizedList: Styled<"native", typeof import("react-native").VirtualizedList, import("react-native").VirtualizedListProps<unknown> & React.RefAttributes<import("react-native").VirtualizedList<unknown>>, object>;
|
|
38
34
|
};
|
|
39
|
-
export {
|
|
35
|
+
export { IStyledComponent, IStyledComponentFactory, IStyledStatics, NativeTarget, StyledOptions, } from '../types';
|
|
40
36
|
export { css, isStyledComponent, ThemeProvider, ThemeConsumer, ThemeContext, withTheme, useTheme };
|
|
41
37
|
export default styled;
|
|
@@ -1,2 +1,48 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tslib = require('tslib');
|
|
6
|
+
var helperModuleImports = require('@babel/helper-module-imports');
|
|
7
|
+
var traverse = require('@babel/traverse');
|
|
8
|
+
var babelPluginMacros = require('babel-plugin-macros');
|
|
9
|
+
var babelPlugin = require('babel-plugin-styled-components');
|
|
10
|
+
|
|
11
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
|
+
|
|
13
|
+
var traverse__default = /*#__PURE__*/_interopDefaultLegacy(traverse);
|
|
14
|
+
var babelPlugin__default = /*#__PURE__*/_interopDefaultLegacy(babelPlugin);
|
|
15
|
+
|
|
16
|
+
function styledComponentsMacro(_a) {
|
|
17
|
+
var references = _a.references, state = _a.state, t = _a.babel.types, _b = _a.config, _c = _b === void 0 ? {} : _b, _d = _c.importModuleName, importModuleName = _d === void 0 ? 'styled-components' : _d, config = tslib.__rest(_c, ["importModuleName"]);
|
|
18
|
+
var program = state.file.path;
|
|
19
|
+
// FIRST STEP : replace `styled-components/macro` by `styled-components
|
|
20
|
+
// references looks like this
|
|
21
|
+
// { default: [path, path], css: [path], ... }
|
|
22
|
+
var customImportName;
|
|
23
|
+
Object.keys(references).forEach(function (refName) {
|
|
24
|
+
// generate new identifier
|
|
25
|
+
var id;
|
|
26
|
+
if (refName === 'default') {
|
|
27
|
+
id = helperModuleImports.addDefault(program, importModuleName, { nameHint: 'styled' });
|
|
28
|
+
customImportName = id;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
id = helperModuleImports.addNamed(program, refName, importModuleName, { nameHint: refName });
|
|
32
|
+
}
|
|
33
|
+
// update references with the new identifiers
|
|
34
|
+
references[refName].forEach(function (referencePath) {
|
|
35
|
+
// eslint-disable-next-line no-param-reassign
|
|
36
|
+
referencePath.node.name = id.name;
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
// SECOND STEP : apply babel-plugin-styled-components to the file
|
|
40
|
+
var stateWithOpts = tslib.__assign(tslib.__assign({}, state), { opts: tslib.__assign(tslib.__assign({}, config), { topLevelImportPaths: (config.topLevelImportPaths || []).concat(importModuleName) }), customImportName: customImportName });
|
|
41
|
+
traverse__default["default"](program.parent, babelPlugin__default["default"]({ types: t }).visitor, undefined, stateWithOpts);
|
|
42
|
+
}
|
|
43
|
+
var index = babelPluginMacros.createMacro(styledComponentsMacro, {
|
|
44
|
+
configName: 'styledComponents',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
exports["default"] = index;
|
|
2
48
|
//# sourceMappingURL=styled-components-macro.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styled-components-macro.cjs.js","sources":["../src/macro/index.ts"],"sourcesContent":["import { types } from '@babel/core';\nimport { addDefault, addNamed } from '@babel/helper-module-imports';\nimport traverse from '@babel/traverse';\nimport { createMacro, MacroParams } from 'babel-plugin-macros';\nimport babelPlugin from 'babel-plugin-styled-components';\n\nfunction styledComponentsMacro({\n references,\n state,\n babel: { types: t },\n config: { importModuleName = 'styled-components', ...config } = {},\n}: MacroParams) {\n const program = state.file.path;\n\n // FIRST STEP : replace `styled-components/macro` by `styled-components\n // references looks like this\n // { default: [path, path], css: [path], ... }\n let customImportName;\n Object.keys(references).forEach(refName => {\n // generate new identifier\n let id: types.Identifier;\n if (refName === 'default') {\n id = addDefault(program, importModuleName, { nameHint: 'styled' });\n customImportName = id;\n } else {\n id = addNamed(program, refName, importModuleName, { nameHint: refName });\n }\n\n // update references with the new identifiers\n references[refName].forEach(referencePath => {\n // eslint-disable-next-line no-param-reassign\n (referencePath.node as types.Identifier).name = id.name;\n });\n });\n\n // SECOND STEP : apply babel-plugin-styled-components to the file\n const stateWithOpts = {\n ...state,\n opts: {\n ...config,\n topLevelImportPaths: (config.topLevelImportPaths || []).concat(importModuleName),\n },\n customImportName,\n };\n traverse(program.parent, babelPlugin({ types: t }).visitor, undefined, stateWithOpts);\n}\n\nexport default createMacro(styledComponentsMacro, {\n configName: 'styledComponents',\n});\n"],"names":["
|
|
1
|
+
{"version":3,"file":"styled-components-macro.cjs.js","sources":["../src/macro/index.ts"],"sourcesContent":["import { types } from '@babel/core';\nimport { addDefault, addNamed } from '@babel/helper-module-imports';\nimport traverse from '@babel/traverse';\nimport { createMacro, MacroParams } from 'babel-plugin-macros';\nimport babelPlugin from 'babel-plugin-styled-components';\n\nfunction styledComponentsMacro({\n references,\n state,\n babel: { types: t },\n config: { importModuleName = 'styled-components', ...config } = {},\n}: MacroParams) {\n const program = state.file.path;\n\n // FIRST STEP : replace `styled-components/macro` by `styled-components\n // references looks like this\n // { default: [path, path], css: [path], ... }\n let customImportName;\n Object.keys(references).forEach(refName => {\n // generate new identifier\n let id: types.Identifier;\n if (refName === 'default') {\n id = addDefault(program, importModuleName, { nameHint: 'styled' });\n customImportName = id;\n } else {\n id = addNamed(program, refName, importModuleName, { nameHint: refName });\n }\n\n // update references with the new identifiers\n references[refName].forEach(referencePath => {\n // eslint-disable-next-line no-param-reassign\n (referencePath.node as types.Identifier).name = id.name;\n });\n });\n\n // SECOND STEP : apply babel-plugin-styled-components to the file\n const stateWithOpts = {\n ...state,\n opts: {\n ...config,\n topLevelImportPaths: (config.topLevelImportPaths || []).concat(importModuleName),\n },\n customImportName,\n };\n traverse(program.parent, babelPlugin({ types: t }).visitor, undefined, stateWithOpts);\n}\n\nexport default createMacro(styledComponentsMacro, {\n configName: 'styledComponents',\n});\n"],"names":["__rest","addDefault","addNamed","__assign","traverse","babelPlugin","createMacro"],"mappings":";;;;;;;;;;;;;;;AAMA,SAAS,qBAAqB,CAAC,EAKjB,EAAA;IAJZ,IAAA,UAAU,GAAA,EAAA,CAAA,UAAA,EACV,KAAK,GAAA,EAAA,CAAA,KAAA,EACW,CAAC,GAAA,EAAA,CAAA,KAAA,CAAA,KAAA,EACjB,EAAA,GAAA,EAAA,CAAA,MAAkE,EAAlE,EAAA,GAAA,EAAA,KAAA,KAAA,CAAA,GAAgE,EAAE,GAAA,EAAA,EAAxD,EAAsC,GAAA,EAAA,CAAA,gBAAA,EAAtC,gBAAgB,GAAA,EAAA,KAAA,KAAA,CAAA,GAAG,mBAAmB,GAAA,EAAA,EAAK,MAAM,GAAnDA,YAAA,CAAA,EAAA,EAAA,CAAA,kBAAA,CAAqD,CAAK,CAAA;AAElE,IAAA,IAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;;;;AAKhC,IAAA,IAAI,gBAAgB,CAAC;IACrB,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,UAAA,OAAO,EAAA;;AAErC,QAAA,IAAI,EAAoB,CAAC;QACzB,IAAI,OAAO,KAAK,SAAS,EAAE;AACzB,YAAA,EAAE,GAAGC,8BAAU,CAAC,OAAO,EAAE,gBAAgB,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;YACnE,gBAAgB,GAAG,EAAE,CAAC;AACvB,SAAA;AAAM,aAAA;AACL,YAAA,EAAE,GAAGC,4BAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;AAC1E,SAAA;;AAGD,QAAA,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,UAAA,aAAa,EAAA;;YAEtC,aAAa,CAAC,IAAyB,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,CAAC;AAC1D,SAAC,CAAC,CAAC;AACL,KAAC,CAAC,CAAC;;IAGH,IAAM,aAAa,GACdC,cAAA,CAAAA,cAAA,CAAA,EAAA,EAAA,KAAK,CACR,EAAA,EAAA,IAAI,EACCA,cAAA,CAAAA,cAAA,CAAA,EAAA,EAAA,MAAM,CACT,EAAA,EAAA,mBAAmB,EAAE,CAAC,MAAM,CAAC,mBAAmB,IAAI,EAAE,EAAE,MAAM,CAAC,gBAAgB,CAAC,EAElF,CAAA,EAAA,gBAAgB,EAAA,gBAAA,EAAA,CACjB,CAAC;IACFC,4BAAQ,CAAC,OAAO,CAAC,MAAM,EAAEC,+BAAW,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;AACxF,CAAC;AAED,YAAeC,6BAAW,CAAC,qBAAqB,EAAE;AAChD,IAAA,UAAU,EAAE,kBAAkB;AAC/B,CAAA,CAAC;;;;"}
|
|
@@ -1,2 +1,39 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { __rest, __assign } from 'tslib';
|
|
2
|
+
import { addDefault, addNamed } from '@babel/helper-module-imports';
|
|
3
|
+
import traverse from '@babel/traverse';
|
|
4
|
+
import { createMacro } from 'babel-plugin-macros';
|
|
5
|
+
import babelPlugin from 'babel-plugin-styled-components';
|
|
6
|
+
|
|
7
|
+
function styledComponentsMacro(_a) {
|
|
8
|
+
var references = _a.references, state = _a.state, t = _a.babel.types, _b = _a.config, _c = _b === void 0 ? {} : _b, _d = _c.importModuleName, importModuleName = _d === void 0 ? 'styled-components' : _d, config = __rest(_c, ["importModuleName"]);
|
|
9
|
+
var program = state.file.path;
|
|
10
|
+
// FIRST STEP : replace `styled-components/macro` by `styled-components
|
|
11
|
+
// references looks like this
|
|
12
|
+
// { default: [path, path], css: [path], ... }
|
|
13
|
+
var customImportName;
|
|
14
|
+
Object.keys(references).forEach(function (refName) {
|
|
15
|
+
// generate new identifier
|
|
16
|
+
var id;
|
|
17
|
+
if (refName === 'default') {
|
|
18
|
+
id = addDefault(program, importModuleName, { nameHint: 'styled' });
|
|
19
|
+
customImportName = id;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
id = addNamed(program, refName, importModuleName, { nameHint: refName });
|
|
23
|
+
}
|
|
24
|
+
// update references with the new identifiers
|
|
25
|
+
references[refName].forEach(function (referencePath) {
|
|
26
|
+
// eslint-disable-next-line no-param-reassign
|
|
27
|
+
referencePath.node.name = id.name;
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
// SECOND STEP : apply babel-plugin-styled-components to the file
|
|
31
|
+
var stateWithOpts = __assign(__assign({}, state), { opts: __assign(__assign({}, config), { topLevelImportPaths: (config.topLevelImportPaths || []).concat(importModuleName) }), customImportName: customImportName });
|
|
32
|
+
traverse(program.parent, babelPlugin({ types: t }).visitor, undefined, stateWithOpts);
|
|
33
|
+
}
|
|
34
|
+
var index = createMacro(styledComponentsMacro, {
|
|
35
|
+
configName: 'styledComponents',
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export { index as default };
|
|
2
39
|
//# sourceMappingURL=styled-components-macro.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styled-components-macro.esm.js","sources":["../src/macro/index.ts"],"sourcesContent":["import { types } from '@babel/core';\nimport { addDefault, addNamed } from '@babel/helper-module-imports';\nimport traverse from '@babel/traverse';\nimport { createMacro, MacroParams } from 'babel-plugin-macros';\nimport babelPlugin from 'babel-plugin-styled-components';\n\nfunction styledComponentsMacro({\n references,\n state,\n babel: { types: t },\n config: { importModuleName = 'styled-components', ...config } = {},\n}: MacroParams) {\n const program = state.file.path;\n\n // FIRST STEP : replace `styled-components/macro` by `styled-components\n // references looks like this\n // { default: [path, path], css: [path], ... }\n let customImportName;\n Object.keys(references).forEach(refName => {\n // generate new identifier\n let id: types.Identifier;\n if (refName === 'default') {\n id = addDefault(program, importModuleName, { nameHint: 'styled' });\n customImportName = id;\n } else {\n id = addNamed(program, refName, importModuleName, { nameHint: refName });\n }\n\n // update references with the new identifiers\n references[refName].forEach(referencePath => {\n // eslint-disable-next-line no-param-reassign\n (referencePath.node as types.Identifier).name = id.name;\n });\n });\n\n // SECOND STEP : apply babel-plugin-styled-components to the file\n const stateWithOpts = {\n ...state,\n opts: {\n ...config,\n topLevelImportPaths: (config.topLevelImportPaths || []).concat(importModuleName),\n },\n customImportName,\n };\n traverse(program.parent, babelPlugin({ types: t }).visitor, undefined, stateWithOpts);\n}\n\nexport default createMacro(styledComponentsMacro, {\n configName: 'styledComponents',\n});\n"],"names":[
|
|
1
|
+
{"version":3,"file":"styled-components-macro.esm.js","sources":["../src/macro/index.ts"],"sourcesContent":["import { types } from '@babel/core';\nimport { addDefault, addNamed } from '@babel/helper-module-imports';\nimport traverse from '@babel/traverse';\nimport { createMacro, MacroParams } from 'babel-plugin-macros';\nimport babelPlugin from 'babel-plugin-styled-components';\n\nfunction styledComponentsMacro({\n references,\n state,\n babel: { types: t },\n config: { importModuleName = 'styled-components', ...config } = {},\n}: MacroParams) {\n const program = state.file.path;\n\n // FIRST STEP : replace `styled-components/macro` by `styled-components\n // references looks like this\n // { default: [path, path], css: [path], ... }\n let customImportName;\n Object.keys(references).forEach(refName => {\n // generate new identifier\n let id: types.Identifier;\n if (refName === 'default') {\n id = addDefault(program, importModuleName, { nameHint: 'styled' });\n customImportName = id;\n } else {\n id = addNamed(program, refName, importModuleName, { nameHint: refName });\n }\n\n // update references with the new identifiers\n references[refName].forEach(referencePath => {\n // eslint-disable-next-line no-param-reassign\n (referencePath.node as types.Identifier).name = id.name;\n });\n });\n\n // SECOND STEP : apply babel-plugin-styled-components to the file\n const stateWithOpts = {\n ...state,\n opts: {\n ...config,\n topLevelImportPaths: (config.topLevelImportPaths || []).concat(importModuleName),\n },\n customImportName,\n };\n traverse(program.parent, babelPlugin({ types: t }).visitor, undefined, stateWithOpts);\n}\n\nexport default createMacro(styledComponentsMacro, {\n configName: 'styledComponents',\n});\n"],"names":[],"mappings":";;;;;;AAMA,SAAS,qBAAqB,CAAC,EAKjB,EAAA;IAJZ,IAAA,UAAU,GAAA,EAAA,CAAA,UAAA,EACV,KAAK,GAAA,EAAA,CAAA,KAAA,EACW,CAAC,GAAA,EAAA,CAAA,KAAA,CAAA,KAAA,EACjB,EAAA,GAAA,EAAA,CAAA,MAAkE,EAAlE,EAAA,GAAA,EAAA,KAAA,KAAA,CAAA,GAAgE,EAAE,GAAA,EAAA,EAAxD,EAAsC,GAAA,EAAA,CAAA,gBAAA,EAAtC,gBAAgB,GAAA,EAAA,KAAA,KAAA,CAAA,GAAG,mBAAmB,GAAA,EAAA,EAAK,MAAM,GAAnD,MAAA,CAAA,EAAA,EAAA,CAAA,kBAAA,CAAqD,CAAK,CAAA;AAElE,IAAA,IAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;;;;AAKhC,IAAA,IAAI,gBAAgB,CAAC;IACrB,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,UAAA,OAAO,EAAA;;AAErC,QAAA,IAAI,EAAoB,CAAC;QACzB,IAAI,OAAO,KAAK,SAAS,EAAE;AACzB,YAAA,EAAE,GAAG,UAAU,CAAC,OAAO,EAAE,gBAAgB,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;YACnE,gBAAgB,GAAG,EAAE,CAAC;AACvB,SAAA;AAAM,aAAA;AACL,YAAA,EAAE,GAAG,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;AAC1E,SAAA;;AAGD,QAAA,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,UAAA,aAAa,EAAA;;YAEtC,aAAa,CAAC,IAAyB,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,CAAC;AAC1D,SAAC,CAAC,CAAC;AACL,KAAC,CAAC,CAAC;;IAGH,IAAM,aAAa,GACd,QAAA,CAAA,QAAA,CAAA,EAAA,EAAA,KAAK,CACR,EAAA,EAAA,IAAI,EACC,QAAA,CAAA,QAAA,CAAA,EAAA,EAAA,MAAM,CACT,EAAA,EAAA,mBAAmB,EAAE,CAAC,MAAM,CAAC,mBAAmB,IAAI,EAAE,EAAE,MAAM,CAAC,gBAAgB,CAAC,EAElF,CAAA,EAAA,gBAAgB,EAAA,gBAAA,EAAA,CACjB,CAAC;IACF,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;AACxF,CAAC;AAED,YAAe,WAAW,CAAC,qBAAqB,EAAE;AAChD,IAAA,UAAU,EAAE,kBAAkB;AAC/B,CAAA,CAAC;;;;"}
|