Skip to content

Commit df6befd

Browse files
committed
refactor: compile to es5
Related to andreypopp#1
1 parent 72dbcf8 commit df6befd

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"babylon": "^6.7.0",
5353
"invariant": "^2.2.1",
5454
"loader-utils": "^0.2.14",
55+
"object-assign": "^4.1.0",
5556
"postcss": "^5.0.19",
5657
"postcss-selector-parser": "^1.3.3"
5758
},

src/index.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import HTMLTagList from './HTMLTagList';
2121
import CSSPseudoClassList from './CSSPseudoClassList';
2222
import * as ComponentRef from './ComponentRef';
2323

24+
2425
type RenderConfig = {
2526
requestCSS: string;
2627
};
@@ -45,6 +46,8 @@ type ComponentSpecCollection = {
4546

4647
const LOADER = require.resolve('../webpack');
4748

49+
const OBJECT_ASSIGN = require.resolve('object-assign');
50+
4851
const COMPONENT_RE = /^[A-Z][a-zA-Z_0-9]*$/;
4952

5053
const PROP_VARIANT_NAME = ':prop';
@@ -219,8 +222,9 @@ function renderToJS(source: string, config: RenderConfig): string {
219222
let root = postcss.parse(source);
220223

221224
let imports = stmt`
222-
import React from "react";
223-
import styles from "${config.requestCSS}";
225+
var React = require("react");
226+
var objectAssign = require("${OBJECT_ASSIGN}");
227+
var styles = require("${config.requestCSS}");
224228
`;
225229
let statements = [];
226230
let components: ComponentSpecCollection = {};
@@ -258,9 +262,7 @@ function renderToJS(source: string, config: RenderConfig): string {
258262
);
259263
base = identifier(componentName + '__Base');
260264
imports.push(stmt`
261-
import {
262-
${identifier(ref.name)} as ${base}
263-
} from "${ref.source}";
265+
var ${base} = require("${ref.source}").${identifier(ref.name)};
264266
`);
265267
}
266268

@@ -316,11 +318,12 @@ function renderToJS(source: string, config: RenderConfig): string {
316318
}
317319
}
318320
statements.push(stmt`
319-
export function ${identifier(componentName)}({variant = {}, ...props}) {
320-
let className = ${className};
321+
module.exports.${identifier(componentName)} = function ${identifier(componentName)}(props) {
322+
var variant = props.variant || {};
323+
var className = ${className};
321324
return React.createElement(
322325
${component.base},
323-
{...props, className}
326+
objectAssign({}, props, {className: className, variant: undefined})
324327
);
325328
}
326329
`);

0 commit comments

Comments
 (0)