taro-css-to-react-native 3.3.11 → 3.3.15

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.
@@ -25,15 +25,25 @@ var TokenStream = /*#__PURE__*/function () {
25
25
  }
26
26
 
27
27
  _createClass(TokenStream, [{
28
+ key: "node",
29
+ get: function get() {
30
+ return this.nodes[this.index];
31
+ }
32
+ }, {
33
+ key: "length",
34
+ get: function get() {
35
+ return this.nodes.length;
36
+ }
37
+ }, {
28
38
  key: "hasTokens",
29
39
  value: function hasTokens() {
30
- return this.index <= this.nodes.length - 1;
40
+ return this.index <= this.length - 1;
31
41
  }
32
42
  }, {
33
43
  key: SYMBOL_MATCH,
34
44
  value: function value() {
35
45
  if (!this.hasTokens()) return null;
36
- var node = this.nodes[this.index];
46
+ var node = this.node;
37
47
 
38
48
  for (var i = 0; i < arguments.length; i += 1) {
39
49
  var tokenDescriptor = i < 0 || arguments.length <= i ? undefined : arguments[i];
@@ -62,7 +72,7 @@ var TokenStream = /*#__PURE__*/function () {
62
72
  }, {
63
73
  key: "matchesFunction",
64
74
  value: function matchesFunction() {
65
- var node = this.nodes[this.index];
75
+ var node = this.node;
66
76
  if (node.type !== 'function') return null;
67
77
  var value = new TokenStream(node.nodes, node);
68
78
  this.index += 1;
@@ -83,7 +93,9 @@ var TokenStream = /*#__PURE__*/function () {
83
93
  }, {
84
94
  key: "throw",
85
95
  value: function _throw() {
86
- throw new Error("Unexpected token type: ".concat(this.nodes[this.index].type));
96
+ var _this$node;
97
+
98
+ throw new Error("Unexpected token type: ".concat((_this$node = this.node) === null || _this$node === void 0 ? void 0 : _this$node.type));
87
99
  }
88
100
  }, {
89
101
  key: "saveRewindPoint",
@@ -30,7 +30,7 @@ var transformRawValue = function transformRawValue(input) {
30
30
  if (numberMatch !== null) {
31
31
  var num = Number(numberMatch[1]);
32
32
 
33
- if (/px/.test(value)) {
33
+ if (/(\d+)px/.test(value)) {
34
34
  return "scalePx2dp(".concat(num, ")");
35
35
  } else {
36
36
  return num;
@@ -62,7 +62,7 @@ var regExpToken = function regExpToken(regExp) {
62
62
  if (match === null) return null;
63
63
  var value = transform(match[1]);
64
64
 
65
- if (/px/.test(node.value)) {
65
+ if (/(\d+)px/.test(node.value)) {
66
66
  return "scalePx2dp(".concat(value, ")");
67
67
  } else {
68
68
  return value;
@@ -50,7 +50,7 @@ var _default = function _default(tokenStream) {
50
50
  while (partsParsed < 2 && tokenStream.hasTokens()) {
51
51
  if (partsParsed !== 0) tokenStream.expect(SPACE);
52
52
 
53
- if (flexGrow === undefined && tokenStream.matches(NUMBER)) {
53
+ if (typeof flexGrow === 'undefined' && tokenStream.matches(NUMBER)) {
54
54
  flexGrow = tokenStream.lastValue;
55
55
  tokenStream.saveRewindPoint();
56
56
 
@@ -59,9 +59,9 @@ var _default = function _default(tokenStream) {
59
59
  } else {
60
60
  tokenStream.rewind();
61
61
  }
62
- } else if (flexBasis === undefined && tokenStream.matches(LENGTH)) {
62
+ } else if (typeof flexBasis === 'undefined' && tokenStream.matches(LENGTH)) {
63
63
  flexBasis = tokenStream.lastValue;
64
- } else if (flexBasis === undefined && tokenStream.matches(AUTO)) {
64
+ } else if (typeof flexBasis === 'undefined' && tokenStream.matches(AUTO)) {
65
65
  flexBasis = 'auto';
66
66
  } else {
67
67
  tokenStream["throw"]();
@@ -71,9 +71,9 @@ var _default = function _default(tokenStream) {
71
71
  }
72
72
 
73
73
  tokenStream.expectEmpty();
74
- if (flexGrow === undefined) flexGrow = defaultFlexGrow;
75
- if (flexShrink === undefined) flexShrink = defaultFlexShrink;
76
- if (flexBasis === undefined) flexBasis = defaultFlexBasis;
74
+ if (typeof flexGrow === 'undefined') flexGrow = defaultFlexGrow;
75
+ if (typeof flexShrink === 'undefined') flexShrink = defaultFlexShrink;
76
+ if (typeof flexBasis === 'undefined') flexBasis = defaultFlexBasis;
77
77
  return {
78
78
  $merge: {
79
79
  flexGrow: flexGrow,
@@ -36,11 +36,11 @@ var _default = function _default(tokenStream) {
36
36
  while (numStyleWeightVariantMatched < 3 && tokenStream.hasTokens()) {
37
37
  if (tokenStream.matches(NORMAL)) {
38
38
  /* pass */
39
- } else if (fontStyle === undefined && tokenStream.matches(STYLE)) {
39
+ } else if (typeof fontStyle === 'undefined' && tokenStream.matches(STYLE)) {
40
40
  fontStyle = tokenStream.lastValue;
41
- } else if (fontWeight === undefined && tokenStream.matches(WEIGHT)) {
41
+ } else if (typeof fontWeight === 'undefined' && tokenStream.matches(WEIGHT)) {
42
42
  fontWeight = tokenStream.lastValue;
43
- } else if (fontVariant === undefined && tokenStream.matches(VARIANT)) {
43
+ } else if (typeof fontVariant === 'undefined' && tokenStream.matches(VARIANT)) {
44
44
  fontVariant = [tokenStream.lastValue];
45
45
  } else {
46
46
  break;
@@ -54,7 +54,8 @@ var _default = function _default(tokenStream) {
54
54
 
55
55
  if (tokenStream.matches(SLASH)) {
56
56
  if (tokenStream.matches(NUMBER)) {
57
- lineHeight = fontSize * tokenStream.lastValue;
57
+ var size = typeof fontSize === 'string' ? fontSize.replace(/scalePx2dp\((\d+)\)/, '$1') : fontSize;
58
+ lineHeight = size * tokenStream.lastValue;
58
59
  } else {
59
60
  lineHeight = tokenStream.expect(LENGTH, UNSUPPORTED_LENGTH_UNIT);
60
61
  }
@@ -62,9 +63,9 @@ var _default = function _default(tokenStream) {
62
63
 
63
64
  tokenStream.expect(SPACE);
64
65
  var fontFamily = (0, _fontFamily["default"])(tokenStream);
65
- if (fontStyle === undefined) fontStyle = defaultFontStyle;
66
- if (fontWeight === undefined) fontWeight = defaultFontWeight;
67
- if (fontVariant === undefined) fontVariant = defaultFontVariant;
66
+ if (typeof fontStyle === 'undefined') fontStyle = defaultFontStyle;
67
+ if (typeof fontWeight === 'undefined') fontWeight = defaultFontWeight;
68
+ if (typeof fontVariant === 'undefined') fontVariant = defaultFontVariant;
68
69
  var out = {
69
70
  fontStyle: fontStyle,
70
71
  fontWeight: fontWeight,
@@ -72,7 +73,7 @@ var _default = function _default(tokenStream) {
72
73
  fontSize: fontSize,
73
74
  fontFamily: fontFamily
74
75
  };
75
- if (lineHeight !== undefined) out.lineHeight = lineHeight;
76
+ if (typeof lineHeight !== 'undefined') out.lineHeight = lineHeight;
76
77
  return {
77
78
  $merge: out
78
79
  };
@@ -24,7 +24,7 @@ var _default = function _default(tokenStream) {
24
24
  while (tokenStream.hasTokens()) {
25
25
  if (didParseFirst) tokenStream.expect(SPACE);
26
26
 
27
- if (line === undefined && tokenStream.matches(LINE)) {
27
+ if (typeof line === 'undefined' && tokenStream.matches(LINE)) {
28
28
  var lines = [tokenStream.lastValue.toLowerCase()];
29
29
  tokenStream.saveRewindPoint();
30
30
 
@@ -37,9 +37,9 @@ var _default = function _default(tokenStream) {
37
37
  }
38
38
 
39
39
  line = lines.join(' ');
40
- } else if (style === undefined && tokenStream.matches(STYLE)) {
40
+ } else if (typeof style === 'undefined' && tokenStream.matches(STYLE)) {
41
41
  style = tokenStream.lastValue;
42
- } else if (color === undefined && tokenStream.matches(COLOR)) {
42
+ } else if (typeof color === 'undefined' && tokenStream.matches(COLOR)) {
43
43
  color = tokenStream.lastValue;
44
44
  } else {
45
45
  tokenStream["throw"]();
@@ -49,9 +49,9 @@ var _default = function _default(tokenStream) {
49
49
  }
50
50
 
51
51
  var $merge = {
52
- textDecorationLine: line !== undefined ? line : defaultTextDecorationLine,
53
- textDecorationColor: color !== undefined ? color : defaultTextDecorationColor,
54
- textDecorationStyle: style !== undefined ? style : defaultTextDecorationStyle
52
+ textDecorationLine: typeof line !== 'undefined' ? line : defaultTextDecorationLine,
53
+ textDecorationColor: typeof color !== 'undefined' ? color : defaultTextDecorationColor,
54
+ textDecorationStyle: typeof style !== 'undefined' ? style : defaultTextDecorationStyle
55
55
  };
56
56
  return {
57
57
  $merge: $merge
@@ -36,7 +36,7 @@ var xyTransformFactory = function xyTransformFactory(tokenType) {
36
36
  if (functionStream.hasTokens()) {
37
37
  functionStream.expect(COMMA);
38
38
  y = functionStream.expect(tokenType);
39
- } else if (valueIfOmitted !== undefined) {
39
+ } else if (typeof valueIfOmitted !== 'undefined') {
40
40
  y = valueIfOmitted;
41
41
  } else {
42
42
  // Assumption, if x === y, then we can omit XY
@@ -76,7 +76,7 @@ var anyOrderFactory = function anyOrderFactory(properties) {
76
76
  return function (tokenStream) {
77
77
  var propertyNames = Object.keys(properties);
78
78
  var values = propertyNames.reduce(function (accum, propertyName) {
79
- accum[propertyName] === undefined; // eslint-disable-line
79
+ typeof accum[propertyName] === 'undefined'; // eslint-disable-line
80
80
 
81
81
  return accum;
82
82
  }, {});
@@ -85,7 +85,7 @@ var anyOrderFactory = function anyOrderFactory(properties) {
85
85
  while (numParsed < propertyNames.length && tokenStream.hasTokens()) {
86
86
  if (numParsed) tokenStream.expect(delim);
87
87
  var matchedPropertyName = propertyNames.find(function (propertyName) {
88
- return values[propertyName] === undefined && properties[propertyName].tokens.some(function (token) {
88
+ return typeof values[propertyName] === 'undefined' && properties[propertyName].tokens.some(function (token) {
89
89
  return tokenStream.matches(token);
90
90
  });
91
91
  });
@@ -101,7 +101,7 @@ var anyOrderFactory = function anyOrderFactory(properties) {
101
101
 
102
102
  tokenStream.expectEmpty();
103
103
  propertyNames.forEach(function (propertyName) {
104
- if (values[propertyName] === undefined) {
104
+ if (typeof values[propertyName] === 'undefined') {
105
105
  values[propertyName] = properties[propertyName]["default"];
106
106
  }
107
107
  });
@@ -150,18 +150,33 @@ var parseShadow = function parseShadow(tokenStream) {
150
150
  while (tokenStream.hasTokens()) {
151
151
  if (didParseFirst) tokenStream.expect(SPACE);
152
152
 
153
- if (offsetX === undefined && tokenStream.matches(LENGTH, UNSUPPORTED_LENGTH_UNIT)) {
153
+ if (typeof offsetX === 'undefined' && tokenStream.matches(LENGTH, UNSUPPORTED_LENGTH_UNIT)) {
154
154
  offsetX = tokenStream.lastValue;
155
- tokenStream.expect(SPACE);
156
- offsetY = tokenStream.expect(LENGTH, UNSUPPORTED_LENGTH_UNIT);
155
+
156
+ if (tokenStream.matches(SPACE) && tokenStream.matches(LENGTH, UNSUPPORTED_LENGTH_UNIT)) {
157
+ offsetY = tokenStream.lastValue;
158
+ } else {
159
+ offsetY = offsetX;
160
+ tokenStream.rewind();
161
+ }
162
+
157
163
  tokenStream.saveRewindPoint();
158
164
 
159
165
  if (tokenStream.matches(SPACE) && tokenStream.matches(LENGTH, UNSUPPORTED_LENGTH_UNIT)) {
166
+ // blur-radius
160
167
  radius = tokenStream.lastValue;
161
168
  } else {
162
169
  tokenStream.rewind();
163
170
  }
164
- } else if (color === undefined && tokenStream.matches(COLOR)) {
171
+
172
+ tokenStream.saveRewindPoint();
173
+
174
+ if (tokenStream.matches(SPACE) && tokenStream.matches(LENGTH, UNSUPPORTED_LENGTH_UNIT)) {// spread-radius
175
+ // 兼容web写法,防止报错
176
+ } else {
177
+ tokenStream.rewind();
178
+ }
179
+ } else if (typeof color === 'undefined' && tokenStream.matches(COLOR)) {
165
180
  color = tokenStream.lastValue;
166
181
  } else {
167
182
  tokenStream["throw"]();
@@ -170,14 +185,14 @@ var parseShadow = function parseShadow(tokenStream) {
170
185
  didParseFirst = true;
171
186
  }
172
187
 
173
- if (offsetX === undefined) tokenStream["throw"]();
188
+ if (typeof offsetX === 'undefined') tokenStream["throw"]();
174
189
  return {
175
190
  offset: {
176
191
  width: offsetX,
177
192
  height: offsetY
178
193
  },
179
- radius: radius !== undefined ? radius : 0,
180
- color: color !== undefined ? color : 'black'
194
+ radius: typeof radius !== 'undefined' ? radius : 0,
195
+ color: typeof color !== 'undefined' ? color : 'black'
181
196
  };
182
197
  };
183
198
 
package/dist/index.js CHANGED
@@ -39,7 +39,9 @@ var percentRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?%)$/;
39
39
  var unsupportedUnitRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?(ch|em|ex|cm|mm|in|pc|pt))$/;
40
40
  var shorthandBorderProps = ['border-radius', 'border-width', 'border-color', 'border-style'];
41
41
 
42
- var transformDecls = function transformDecls(styles, declarations, result, options) {
42
+ var transformDecls = function transformDecls(styles, declarations, result) {
43
+ var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
44
+
43
45
  for (var d in declarations) {
44
46
  var declaration = declarations[d];
45
47
  if (declaration.type !== 'declaration') continue;
@@ -60,8 +62,8 @@ var transformDecls = function transformDecls(styles, declarations, result, optio
60
62
  // do not be wrapped by scalePx2dp function
61
63
 
62
64
 
63
- if (!options.scalable && isLengthUnit && /px/.test(value)) {
64
- value = value.replace(/px/g, 'PX');
65
+ if (isLengthUnit && typeof options.scalable === 'boolean' && !options.scalable && /(\d+)px/.test(value)) {
66
+ value = value.replace(/(\d+)px/, '$1PX');
65
67
  }
66
68
 
67
69
  if (shorthandBorderProps.indexOf(property) > -1) {
@@ -102,7 +104,7 @@ var transform = function transform(css, options) {
102
104
  rule.declarations.forEach(function (_ref) {
103
105
  var property = _ref.property,
104
106
  value = _ref.value;
105
- var isAlreadyDefinedAsClass = result[property] !== undefined && result.__exportProps[property] === undefined;
107
+ var isAlreadyDefinedAsClass = typeof result[property] !== 'undefined' && typeof result.__exportProps[property] === 'undefined';
106
108
 
107
109
  if (isAlreadyDefinedAsClass) {
108
110
  throw new Error("Failed to parse :export block because a CSS class in the same file is already using the name \"".concat(property, "\""));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "taro-css-to-react-native",
3
3
  "description": "Convert CSS text to a React Native stylesheet object",
4
- "version": "3.3.11",
4
+ "version": "3.3.15",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",
7
7
  "dependencies": {
@@ -63,5 +63,5 @@
63
63
  "CHANGELOG.md",
64
64
  "README.md"
65
65
  ],
66
- "gitHead": "dad3664e58bb1fe7ab752365d9cc0d0dd444c40a"
66
+ "gitHead": "4a11ab9a8950f6a580e1278c160f6b4aaa8ac4f2"
67
67
  }
@@ -9,14 +9,22 @@ export default class TokenStream {
9
9
  this.rewindIndex = -1
10
10
  }
11
11
 
12
+ get node () {
13
+ return this.nodes[this.index]
14
+ }
15
+
16
+ get length () {
17
+ return this.nodes.length
18
+ }
19
+
12
20
  hasTokens () {
13
- return this.index <= this.nodes.length - 1
21
+ return this.index <= this.length - 1
14
22
  }
15
23
 
16
24
  [SYMBOL_MATCH] (...tokenDescriptors) {
17
25
  if (!this.hasTokens()) return null
18
26
 
19
- const node = this.nodes[this.index]
27
+ const node = this.node
20
28
 
21
29
  for (let i = 0; i < tokenDescriptors.length; i += 1) {
22
30
  const tokenDescriptor = tokenDescriptors[i]
@@ -41,7 +49,7 @@ export default class TokenStream {
41
49
  }
42
50
 
43
51
  matchesFunction () {
44
- const node = this.nodes[this.index]
52
+ const node = this.node
45
53
  if (node.type !== 'function') return null
46
54
  const value = new TokenStream(node.nodes, node)
47
55
  this.index += 1
@@ -59,7 +67,7 @@ export default class TokenStream {
59
67
  }
60
68
 
61
69
  throw () {
62
- throw new Error(`Unexpected token type: ${this.nodes[this.index].type}`)
70
+ throw new Error(`Unexpected token type: ${this.node?.type}`)
63
71
  }
64
72
 
65
73
  saveRewindPoint () {
@@ -17,7 +17,7 @@ export const transformRawValue = input => {
17
17
  const numberMatch = value.match(numberOrLengthRe)
18
18
  if (numberMatch !== null) {
19
19
  const num = Number(numberMatch[1])
20
- if (/px/.test(value)) {
20
+ if (/(\d+)px/.test(value)) {
21
21
  return `scalePx2dp(${num})`
22
22
  } else {
23
23
  return num
@@ -45,7 +45,7 @@ export const regExpToken = (regExp, transform = String) => node => {
45
45
  if (match === null) return null
46
46
 
47
47
  const value = transform(match[1])
48
- if (/px/.test(node.value)) {
48
+ if (/(\d+)px/.test(node.value)) {
49
49
  return `scalePx2dp(${value})`
50
50
  } else {
51
51
  return value
@@ -26,7 +26,7 @@ export default tokenStream => {
26
26
  while (partsParsed < 2 && tokenStream.hasTokens()) {
27
27
  if (partsParsed !== 0) tokenStream.expect(SPACE)
28
28
 
29
- if (flexGrow === undefined && tokenStream.matches(NUMBER)) {
29
+ if (typeof flexGrow === 'undefined' && tokenStream.matches(NUMBER)) {
30
30
  flexGrow = tokenStream.lastValue
31
31
 
32
32
  tokenStream.saveRewindPoint()
@@ -35,9 +35,9 @@ export default tokenStream => {
35
35
  } else {
36
36
  tokenStream.rewind()
37
37
  }
38
- } else if (flexBasis === undefined && tokenStream.matches(LENGTH)) {
38
+ } else if (typeof flexBasis === 'undefined' && tokenStream.matches(LENGTH)) {
39
39
  flexBasis = tokenStream.lastValue
40
- } else if (flexBasis === undefined && tokenStream.matches(AUTO)) {
40
+ } else if (typeof flexBasis === 'undefined' && tokenStream.matches(AUTO)) {
41
41
  flexBasis = 'auto'
42
42
  } else {
43
43
  tokenStream.throw()
@@ -48,9 +48,9 @@ export default tokenStream => {
48
48
 
49
49
  tokenStream.expectEmpty()
50
50
 
51
- if (flexGrow === undefined) flexGrow = defaultFlexGrow
52
- if (flexShrink === undefined) flexShrink = defaultFlexShrink
53
- if (flexBasis === undefined) flexBasis = defaultFlexBasis
51
+ if (typeof flexGrow === 'undefined') flexGrow = defaultFlexGrow
52
+ if (typeof flexShrink === 'undefined') flexShrink = defaultFlexShrink
53
+ if (typeof flexBasis === 'undefined') flexBasis = defaultFlexBasis
54
54
 
55
55
  return { $merge: { flexGrow, flexShrink, flexBasis } }
56
56
  }
@@ -23,11 +23,11 @@ export default tokenStream => {
23
23
  while (numStyleWeightVariantMatched < 3 && tokenStream.hasTokens()) {
24
24
  if (tokenStream.matches(NORMAL)) {
25
25
  /* pass */
26
- } else if (fontStyle === undefined && tokenStream.matches(STYLE)) {
26
+ } else if (typeof fontStyle === 'undefined' && tokenStream.matches(STYLE)) {
27
27
  fontStyle = tokenStream.lastValue
28
- } else if (fontWeight === undefined && tokenStream.matches(WEIGHT)) {
28
+ } else if (typeof fontWeight === 'undefined' && tokenStream.matches(WEIGHT)) {
29
29
  fontWeight = tokenStream.lastValue
30
- } else if (fontVariant === undefined && tokenStream.matches(VARIANT)) {
30
+ } else if (typeof fontVariant === 'undefined' && tokenStream.matches(VARIANT)) {
31
31
  fontVariant = [tokenStream.lastValue]
32
32
  } else {
33
33
  break
@@ -41,7 +41,8 @@ export default tokenStream => {
41
41
 
42
42
  if (tokenStream.matches(SLASH)) {
43
43
  if (tokenStream.matches(NUMBER)) {
44
- lineHeight = fontSize * tokenStream.lastValue
44
+ const size = typeof fontSize === 'string' ? fontSize.replace(/scalePx2dp\((\d+)\)/, '$1') : fontSize
45
+ lineHeight = size * tokenStream.lastValue
45
46
  } else {
46
47
  lineHeight = tokenStream.expect(LENGTH, UNSUPPORTED_LENGTH_UNIT)
47
48
  }
@@ -51,12 +52,12 @@ export default tokenStream => {
51
52
 
52
53
  const fontFamily = parseFontFamily(tokenStream)
53
54
 
54
- if (fontStyle === undefined) fontStyle = defaultFontStyle
55
- if (fontWeight === undefined) fontWeight = defaultFontWeight
56
- if (fontVariant === undefined) fontVariant = defaultFontVariant
55
+ if (typeof fontStyle === 'undefined') fontStyle = defaultFontStyle
56
+ if (typeof fontWeight === 'undefined') fontWeight = defaultFontWeight
57
+ if (typeof fontVariant === 'undefined') fontVariant = defaultFontVariant
57
58
 
58
59
  const out = { fontStyle, fontWeight, fontVariant, fontSize, fontFamily }
59
- if (lineHeight !== undefined) out.lineHeight = lineHeight
60
+ if (typeof lineHeight !== 'undefined') out.lineHeight = lineHeight
60
61
 
61
62
  return { $merge: out }
62
63
  }
@@ -17,7 +17,7 @@ export default tokenStream => {
17
17
  while (tokenStream.hasTokens()) {
18
18
  if (didParseFirst) tokenStream.expect(SPACE)
19
19
 
20
- if (line === undefined && tokenStream.matches(LINE)) {
20
+ if (typeof line === 'undefined' && tokenStream.matches(LINE)) {
21
21
  const lines = [tokenStream.lastValue.toLowerCase()]
22
22
 
23
23
  tokenStream.saveRewindPoint()
@@ -34,9 +34,9 @@ export default tokenStream => {
34
34
  }
35
35
 
36
36
  line = lines.join(' ')
37
- } else if (style === undefined && tokenStream.matches(STYLE)) {
37
+ } else if (typeof style === 'undefined' && tokenStream.matches(STYLE)) {
38
38
  style = tokenStream.lastValue
39
- } else if (color === undefined && tokenStream.matches(COLOR)) {
39
+ } else if (typeof color === 'undefined' && tokenStream.matches(COLOR)) {
40
40
  color = tokenStream.lastValue
41
41
  } else {
42
42
  tokenStream.throw()
@@ -46,11 +46,11 @@ export default tokenStream => {
46
46
  }
47
47
 
48
48
  const $merge = {
49
- textDecorationLine: line !== undefined ? line : defaultTextDecorationLine,
49
+ textDecorationLine: typeof line !== 'undefined' ? line : defaultTextDecorationLine,
50
50
  textDecorationColor:
51
- color !== undefined ? color : defaultTextDecorationColor,
51
+ typeof color !== 'undefined' ? color : defaultTextDecorationColor,
52
52
  textDecorationStyle:
53
- style !== undefined ? style : defaultTextDecorationStyle
53
+ typeof style !== 'undefined' ? style : defaultTextDecorationStyle
54
54
  }
55
55
  return { $merge }
56
56
  }
@@ -21,7 +21,7 @@ const xyTransformFactory = tokenType => (
21
21
  if (functionStream.hasTokens()) {
22
22
  functionStream.expect(COMMA)
23
23
  y = functionStream.expect(tokenType)
24
- } else if (valueIfOmitted !== undefined) {
24
+ } else if (typeof valueIfOmitted !== 'undefined') {
25
25
  y = valueIfOmitted
26
26
  } else {
27
27
  // Assumption, if x === y, then we can omit XY
@@ -37,7 +37,7 @@ export const directionFactory = ({
37
37
  export const anyOrderFactory = (properties, delim = SPACE) => tokenStream => {
38
38
  const propertyNames = Object.keys(properties)
39
39
  const values = propertyNames.reduce((accum, propertyName) => {
40
- accum[propertyName] === undefined; // eslint-disable-line
40
+ typeof accum[propertyName] === 'undefined'; // eslint-disable-line
41
41
  return accum
42
42
  }, {})
43
43
 
@@ -47,7 +47,7 @@ export const anyOrderFactory = (properties, delim = SPACE) => tokenStream => {
47
47
 
48
48
  const matchedPropertyName = propertyNames.find(
49
49
  propertyName =>
50
- values[propertyName] === undefined &&
50
+ typeof values[propertyName] === 'undefined' &&
51
51
  properties[propertyName].tokens.some(token =>
52
52
  tokenStream.matches(token)
53
53
  )
@@ -65,7 +65,9 @@ export const anyOrderFactory = (properties, delim = SPACE) => tokenStream => {
65
65
  tokenStream.expectEmpty()
66
66
 
67
67
  propertyNames.forEach(propertyName => {
68
- if (values[propertyName] === undefined) { values[propertyName] = properties[propertyName].default }
68
+ if (typeof values[propertyName] === 'undefined') {
69
+ values[propertyName] = properties[propertyName].default
70
+ }
69
71
  })
70
72
 
71
73
  return { $merge: values }
@@ -100,23 +102,41 @@ export const parseShadow = tokenStream => {
100
102
  if (didParseFirst) tokenStream.expect(SPACE)
101
103
 
102
104
  if (
103
- offsetX === undefined &&
105
+ typeof offsetX === 'undefined' &&
104
106
  tokenStream.matches(LENGTH, UNSUPPORTED_LENGTH_UNIT)
105
107
  ) {
106
108
  offsetX = tokenStream.lastValue
107
- tokenStream.expect(SPACE)
108
- offsetY = tokenStream.expect(LENGTH, UNSUPPORTED_LENGTH_UNIT)
109
+ if (
110
+ tokenStream.matches(SPACE) &&
111
+ tokenStream.matches(LENGTH, UNSUPPORTED_LENGTH_UNIT)
112
+ ) {
113
+ offsetY = tokenStream.lastValue
114
+ } else {
115
+ offsetY = offsetX
116
+ tokenStream.rewind()
117
+ }
109
118
 
110
119
  tokenStream.saveRewindPoint()
111
120
  if (
112
121
  tokenStream.matches(SPACE) &&
113
122
  tokenStream.matches(LENGTH, UNSUPPORTED_LENGTH_UNIT)
114
123
  ) {
124
+ // blur-radius
115
125
  radius = tokenStream.lastValue
116
126
  } else {
117
127
  tokenStream.rewind()
118
128
  }
119
- } else if (color === undefined && tokenStream.matches(COLOR)) {
129
+ tokenStream.saveRewindPoint()
130
+ if (
131
+ tokenStream.matches(SPACE) &&
132
+ tokenStream.matches(LENGTH, UNSUPPORTED_LENGTH_UNIT)
133
+ ) {
134
+ // spread-radius
135
+ // 兼容web写法,防止报错
136
+ } else {
137
+ tokenStream.rewind()
138
+ }
139
+ } else if (typeof color === 'undefined' && tokenStream.matches(COLOR)) {
120
140
  color = tokenStream.lastValue
121
141
  } else {
122
142
  tokenStream.throw()
@@ -125,11 +145,11 @@ export const parseShadow = tokenStream => {
125
145
  didParseFirst = true
126
146
  }
127
147
 
128
- if (offsetX === undefined) tokenStream.throw()
148
+ if (typeof offsetX === 'undefined') tokenStream.throw()
129
149
 
130
150
  return {
131
151
  offset: { width: offsetX, height: offsetY },
132
- radius: radius !== undefined ? radius : 0,
133
- color: color !== undefined ? color : 'black'
152
+ radius: typeof radius !== 'undefined' ? radius : 0,
153
+ color: typeof color !== 'undefined' ? color : 'black'
134
154
  }
135
155
  }
package/src/index.js CHANGED
@@ -23,7 +23,7 @@ const shorthandBorderProps = [
23
23
  'border-style'
24
24
  ]
25
25
 
26
- const transformDecls = (styles, declarations, result, options) => {
26
+ const transformDecls = (styles, declarations, result, options = {}) => {
27
27
  for (const d in declarations) {
28
28
  const declaration = declarations[d]
29
29
  if (declaration.type !== 'declaration') continue
@@ -52,11 +52,12 @@ const transformDecls = (styles, declarations, result, options) => {
52
52
  // scalable option, when it is false, transform single value 'px' unit to 'PX'
53
53
  // do not be wrapped by scalePx2dp function
54
54
  if (
55
- !options.scalable &&
56
55
  isLengthUnit &&
57
- /px/.test(value)
56
+ typeof options.scalable === 'boolean' &&
57
+ !options.scalable &&
58
+ /(\d+)px/.test(value)
58
59
  ) {
59
- value = value.replace(/px/g, 'PX')
60
+ value = value.replace(/(\d+)px/, '$1PX')
60
61
  }
61
62
 
62
63
  if (shorthandBorderProps.indexOf(property) > -1) {
@@ -93,8 +94,8 @@ const transform = (css, options) => {
93
94
 
94
95
  rule.declarations.forEach(({ property, value }) => {
95
96
  const isAlreadyDefinedAsClass =
96
- result[property] !== undefined &&
97
- result.__exportProps[property] === undefined
97
+ typeof result[property] !== 'undefined' &&
98
+ typeof result.__exportProps[property] === 'undefined'
98
99
 
99
100
  if (isAlreadyDefinedAsClass) {
100
101
  throw new Error(