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.
Files changed (68) hide show
  1. package/dist/constructors/constructWithOptions.d.ts +26 -30
  2. package/dist/constructors/createGlobalStyle.d.ts +2 -2
  3. package/dist/constructors/css.d.ts +2 -2
  4. package/dist/constructors/keyframes.d.ts +1 -1
  5. package/dist/constructors/styled.d.ts +177 -181
  6. package/dist/hoc/withTheme.d.ts +2 -2
  7. package/dist/models/GlobalStyle.d.ts +1 -1
  8. package/dist/models/InlineStyle.d.ts +1 -1
  9. package/dist/models/StyledComponent.d.ts +1 -1
  10. package/dist/models/StyledNativeComponent.d.ts +2 -2
  11. package/dist/native/index.d.ts +27 -31
  12. package/dist/styled-components-macro.cjs.js +47 -1
  13. package/dist/styled-components-macro.cjs.js.map +1 -1
  14. package/dist/styled-components-macro.esm.js +38 -1
  15. package/dist/styled-components-macro.esm.js.map +1 -1
  16. package/dist/styled-components.browser.cjs.js +1848 -1
  17. package/dist/styled-components.browser.cjs.js.map +1 -1
  18. package/dist/styled-components.browser.esm.js +1823 -1
  19. package/dist/styled-components.browser.esm.js.map +1 -1
  20. package/dist/styled-components.cjs.js +1868 -1
  21. package/dist/styled-components.cjs.js.map +1 -1
  22. package/dist/styled-components.esm.js +1843 -1
  23. package/dist/styled-components.esm.js.map +1 -1
  24. package/dist/styled-components.js +2068 -1
  25. package/dist/styled-components.js.map +1 -1
  26. package/dist/styled-components.min.js +1 -1
  27. package/dist/styled-components.min.js.map +1 -1
  28. package/dist/test/utils.d.ts +176 -180
  29. package/dist/tsconfig.tsbuildinfo +1 -1
  30. package/dist/types.d.ts +63 -68
  31. package/dist/utils/determineTheme.d.ts +2 -2
  32. package/dist/utils/empties.d.ts +2 -2
  33. package/dist/utils/flatten.d.ts +3 -3
  34. package/dist/utils/generateDisplayName.d.ts +1 -1
  35. package/dist/utils/getComponentName.d.ts +1 -1
  36. package/dist/utils/interleave.d.ts +1 -1
  37. package/dist/utils/isStaticRules.d.ts +1 -1
  38. package/dist/utils/isStyledComponent.d.ts +1 -1
  39. package/dist/utils/isTag.d.ts +1 -1
  40. package/dist/utils/mixinDeep.d.ts +2 -2
  41. package/native/dist/constructors/constructWithOptions.d.ts +26 -30
  42. package/native/dist/constructors/createGlobalStyle.d.ts +2 -2
  43. package/native/dist/constructors/css.d.ts +2 -2
  44. package/native/dist/constructors/keyframes.d.ts +1 -1
  45. package/native/dist/constructors/styled.d.ts +177 -181
  46. package/native/dist/hoc/withTheme.d.ts +2 -2
  47. package/native/dist/models/GlobalStyle.d.ts +1 -1
  48. package/native/dist/models/InlineStyle.d.ts +1 -1
  49. package/native/dist/models/StyledComponent.d.ts +1 -1
  50. package/native/dist/models/StyledNativeComponent.d.ts +2 -2
  51. package/native/dist/native/index.d.ts +27 -31
  52. package/native/dist/styled-components.native.cjs.js +15 -26
  53. package/native/dist/styled-components.native.cjs.js.map +1 -1
  54. package/native/dist/styled-components.native.esm.js +15 -26
  55. package/native/dist/styled-components.native.esm.js.map +1 -1
  56. package/native/dist/test/utils.d.ts +176 -180
  57. package/native/dist/types.d.ts +63 -68
  58. package/native/dist/utils/determineTheme.d.ts +2 -2
  59. package/native/dist/utils/empties.d.ts +2 -2
  60. package/native/dist/utils/flatten.d.ts +3 -3
  61. package/native/dist/utils/generateDisplayName.d.ts +1 -1
  62. package/native/dist/utils/getComponentName.d.ts +1 -1
  63. package/native/dist/utils/interleave.d.ts +1 -1
  64. package/native/dist/utils/isStaticRules.d.ts +1 -1
  65. package/native/dist/utils/isStyledComponent.d.ts +1 -1
  66. package/native/dist/utils/isTag.d.ts +1 -1
  67. package/native/dist/utils/mixinDeep.d.ts +2 -2
  68. package/package.json +2 -3
@@ -1,3 +1,3 @@
1
1
  import React from 'react';
2
- import { AnyComponent, ExecutionContext } from '../types';
3
- export default function withTheme<T extends AnyComponent>(Component: T): React.ForwardRefExoticComponent<React.PropsWithoutRef<JSX.LibraryManagedAttributes<T, ExecutionContext>> & 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]; };
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 = unknown> {
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 = unknown>(styleSheet: StyleSheet): IInlineStyleConstructor<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 = unknown, Statics = unknown>(target: Target, options: StyledOptions<OuterProps>, rules: RuleSet<OuterProps>): ReturnType<IStyledComponentFactory<Target, OuterProps, Statics>>;
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 { ExtensibleObject, IInlineStyleConstructor, IStyledNativeComponent, IStyledNativeComponentFactory, NativeTarget, RuleSet, StyledNativeOptions } from '../types';
2
- declare const _default: (InlineStyle: IInlineStyleConstructor<any>) => <Target extends NativeTarget, OuterProps extends ExtensibleObject, Statics = unknown>(target: Target, options: StyledNativeOptions<OuterProps>, rules: RuleSet<OuterProps>) => IStyledNativeComponent<Target, OuterProps> & Statics;
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;
@@ -1,41 +1,37 @@
1
1
  import React from 'react';
2
- import { NativeStyled } from '../constructors/constructWithOptions';
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
- <Props = unknown, Statics = unknown>(initialStyles: import("../types").Styles<(Target extends import("../types").KnownTarget ? React.ComponentProps<Target> : unknown) & Props>, ...interpolations: import("../types").Interpolation<import("../types").ExecutionContext & (Target extends import("../types").KnownTarget ? React.ComponentProps<Target> : unknown) & Props>[]): import("../types").IStyledNativeComponent<Target, (Target extends import("../types").KnownTarget ? React.ComponentProps<Target> : unknown) & Props> & Statics;
11
- attrs(attrs: import("../types").Attrs<import("../types").ExecutionContext & (Target extends import("../types").KnownTarget ? React.ComponentProps<Target> : unknown)>): any;
12
- withConfig(config: import("../types").StyledNativeOptions<Target extends import("../types").KnownTarget ? React.ComponentProps<Target> : unknown>): any;
13
- }) & {
14
- ActivityIndicator: NativeStyled<typeof import("react-native").ActivityIndicator, import("react-native").ActivityIndicatorProps, unknown, unknown>;
15
- Button: NativeStyled<typeof import("react-native").Button, import("react-native").ButtonProps, unknown, unknown>;
16
- DatePickerIOS: NativeStyled<typeof import("react-native").DatePickerIOS, import("react-native").DatePickerIOSProps, unknown, unknown>;
17
- DrawerLayoutAndroid: NativeStyled<typeof import("react-native").DrawerLayoutAndroid, import("react-native").DrawerLayoutAndroidProps, unknown, unknown>;
18
- FlatList: NativeStyled<typeof import("react-native").FlatList, import("react-native").FlatListProps<unknown>, unknown, unknown>;
19
- Image: NativeStyled<typeof import("react-native").Image, import("react-native").ImageProps, unknown, unknown>;
20
- ImageBackground: NativeStyled<typeof import("react-native").ImageBackground, import("react-native").ImageBackgroundProps, unknown, unknown>;
21
- KeyboardAvoidingView: NativeStyled<typeof import("react-native").KeyboardAvoidingView, import("react-native").KeyboardAvoidingViewProps, unknown, unknown>;
22
- Modal: NativeStyled<typeof import("react-native").Modal, import("react-native").ModalProps, unknown, unknown>;
23
- Pressable: NativeStyled<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>, unknown, unknown>;
24
- ProgressBarAndroid: NativeStyled<typeof import("react-native").ProgressBarAndroid, import("react-native").ProgressBarAndroidProps, unknown, unknown>;
25
- ProgressViewIOS: NativeStyled<typeof import("react-native").ProgressViewIOS, import("react-native").ProgressViewIOSProps, unknown, unknown>;
26
- RefreshControl: NativeStyled<typeof import("react-native").RefreshControl, import("react-native").RefreshControlProps, unknown, unknown>;
27
- SafeAreaView: NativeStyled<typeof import("react-native").SafeAreaView, import("react-native").ViewProps, unknown, unknown>;
28
- ScrollView: NativeStyled<typeof import("react-native").ScrollView, import("react-native").ScrollViewProps, unknown, unknown>;
29
- SectionList: NativeStyled<typeof import("react-native").SectionList, import("react-native").SectionListProps<unknown, unknown>, unknown, unknown>;
30
- Slider: NativeStyled<typeof import("react-native").Slider, import("react-native").SliderProps, unknown, unknown>;
31
- Switch: NativeStyled<typeof import("react-native").Switch, import("react-native").SwitchProps, unknown, unknown>;
32
- Text: NativeStyled<typeof import("react-native").Text, import("react-native").TextProps, unknown, unknown>;
33
- TextInput: NativeStyled<typeof import("react-native").TextInput, import("react-native").TextInputProps, unknown, unknown>;
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 { IStyledNativeComponent, IStyledNativeComponentFactory, IStyledNativeStatics, NativeTarget, StyledNativeOptions, } from '../types';
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
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("@babel/helper-module-imports"),a=require("@babel/traverse"),o=require("babel-plugin-macros"),r=require("babel-plugin-styled-components");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=/*#__PURE__*/n(a),i=/*#__PURE__*/n(r),l=o.createMacro(function(a){var o,r=a.references,n=a.state,l=a.babel.types,u=a.config,d=void 0===u?{}:u,p=d.importModuleName,c=void 0===p?"styled-components":p,m=e.__rest(d,["importModuleName"]),f=n.file.path;Object.keys(r).forEach(function(e){var a;"default"===e?(a=t.addDefault(f,c,{nameHint:"styled"}),o=a):a=t.addNamed(f,e,c,{nameHint:e}),r[e].forEach(function(e){e.node.name=a.name})});var b=e.__assign(e.__assign({},n),{opts:e.__assign(e.__assign({},m),{topLevelImportPaths:(m.topLevelImportPaths||[]).concat(c)}),customImportName:o});s.default(f.parent,i.default({types:l}).visitor,void 0,b)},{configName:"styledComponents"});exports.default=l;
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":["createMacro","_a","customImportName","references","state","t","babel","types","_b","config","_c","_d","importModuleName","__rest","program","file","path","Object","keys","forEach","refName","id","addDefault","nameHint","addNamed","referencePath","node","name","stateWithOpts","__assign","opts","topLevelImportPaths","concat","traverse","parent","babelPlugin","visitor","undefined","configName"],"mappings":"mWA+CeA,EAAAA,EAAAA,YAzCf,SAA+BC,GAC7B,IAUIC,EAVJC,EAAUF,EAAAE,WACVC,EAAKH,EAAAG,MACWC,EAACJ,EAAAK,MAAAC,MACjBC,EAAAP,EAAAQ,OAAAC,OAAA,IAAAF,EAAgE,GAAEA,EAAxDG,EAAsCD,EAAAE,iBAAtCA,OAAgB,IAAAD,EAAG,oBAAmBA,EAAKF,EAA7CI,EAAAA,OAAAH,EAAA,CAAA,qBAEFI,EAAUV,EAAMW,KAAKC,KAM3BC,OAAOC,KAAKf,GAAYgB,QAAQ,SAAAC,GAE9B,IAAIC,EACY,YAAZD,GACFC,EAAKC,EAAUA,WAACR,EAASF,EAAkB,CAAEW,SAAU,WACvDrB,EAAmBmB,GAEnBA,EAAKG,EAAAA,SAASV,EAASM,EAASR,EAAkB,CAAEW,SAAUH,IAIhEjB,EAAWiB,GAASD,QAAQ,SAAAM,GAEzBA,EAAcC,KAA0BC,KAAON,EAAGM,SAKvD,IAAMC,EACDC,EAAAA,SAAAA,EAAAA,SAAA,GAAAzB,GACH,CAAA0B,KACKD,EAAAA,SAAAA,EAAAA,SAAA,GAAApB,GACH,CAAAsB,qBAAsBtB,EAAOsB,qBAAuB,IAAIC,OAAOpB,KAEjEV,iBAAgBA,IAElB+B,EAAAA,QAASnB,EAAQoB,OAAQC,EAAAA,QAAY,CAAE5B,MAAOF,IAAK+B,aAASC,EAAWT,IAGvB,CAChDU,WAAY"}
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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AI,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{__rest as e,__assign as o}from"tslib";import{addDefault as t,addNamed as r}from"@babel/helper-module-imports";import a from"@babel/traverse";import{createMacro as m}from"babel-plugin-macros";import n from"babel-plugin-styled-components";var p=m(function(m){var p,i=m.references,s=m.state,l=m.babel.types,f=m.config,c=void 0===f?{}:f,d=c.importModuleName,b=void 0===d?"styled-components":d,u=e(c,["importModuleName"]),v=s.file.path;Object.keys(i).forEach(function(e){var o;"default"===e?(o=t(v,b,{nameHint:"styled"}),p=o):o=r(v,e,b,{nameHint:e}),i[e].forEach(function(e){e.node.name=o.name})});var y=o(o({},s),{opts:o(o({},u),{topLevelImportPaths:(u.topLevelImportPaths||[]).concat(b)}),customImportName:p});a(v.parent,n({types:l}).visitor,void 0,y)},{configName:"styledComponents"});export{p as default};
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":["index","createMacro","_a","customImportName","references","state","t","babel","types","_b","config","_c","_d","importModuleName","__rest","program","file","path","Object","keys","forEach","refName","id","addDefault","nameHint","addNamed","referencePath","node","name","stateWithOpts","__assign","opts","topLevelImportPaths","concat","traverse","parent","babelPlugin","visitor","undefined","configName"],"mappings":"oPA+CA,IAAeA,EAAAC,EAzCf,SAA+BC,GAC7B,IAUIC,EAVJC,EAAUF,EAAAE,WACVC,EAAKH,EAAAG,MACWC,EAACJ,EAAAK,MAAAC,MACjBC,EAAAP,EAAAQ,OAAAC,OAAA,IAAAF,EAAgE,GAAEA,EAAxDG,EAAsCD,EAAAE,iBAAtCA,OAAgB,IAAAD,EAAG,oBAAmBA,EAAKF,EAA7CI,EAAAH,EAAA,CAAA,qBAEFI,EAAUV,EAAMW,KAAKC,KAM3BC,OAAOC,KAAKf,GAAYgB,QAAQ,SAAAC,GAE9B,IAAIC,EACY,YAAZD,GACFC,EAAKC,EAAWR,EAASF,EAAkB,CAAEW,SAAU,WACvDrB,EAAmBmB,GAEnBA,EAAKG,EAASV,EAASM,EAASR,EAAkB,CAAEW,SAAUH,IAIhEjB,EAAWiB,GAASD,QAAQ,SAAAM,GAEzBA,EAAcC,KAA0BC,KAAON,EAAGM,SAKvD,IAAMC,EACDC,EAAAA,EAAA,GAAAzB,GACH,CAAA0B,KACKD,EAAAA,EAAA,GAAApB,GACH,CAAAsB,qBAAsBtB,EAAOsB,qBAAuB,IAAIC,OAAOpB,KAEjEV,iBAAgBA,IAElB+B,EAASnB,EAAQoB,OAAQC,EAAY,CAAE5B,MAAOF,IAAK+B,aAASC,EAAWT,IAGvB,CAChDU,WAAY"}
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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