Skip to content

Commit c537d61

Browse files
authored
Merge pull request #32 from evcohen/object-assign
use object.assign to support node versions 0.10 and 0.12. Fixes #31.
2 parents c5755ca + edc00d4 commit c537d61

File tree

6 files changed

+70
-29
lines changed

6 files changed

+70
-29
lines changed

.babelrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"presets": ["es2015"]
2+
"presets": ["env"],
3+
"plugins": [
4+
["transform-replace-object-assign", { "moduleSpecifier": "object.assign" }],
5+
],
36
}

.travis.yml

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,36 @@
11
language: node_js
2+
os:
3+
- linux
24
node_js:
3-
- 4
4-
- 5
5-
- 6
5+
- "12"
6+
- "10"
7+
- "8"
8+
- "6"
9+
- "4"
10+
- "0.12"
11+
- "0.10"
612
cache:
7-
yarn: true
813
directories:
914
- node_modules
1015
after_success:
1116
- npm run coveralls
17+
before_install:
18+
- 'case "${TRAVIS_NODE_VERSION}" in 0.*) export NPM_CONFIG_STRICT_SSL=false ;; esac'
19+
- 'nvm install-latest-npm'
20+
install:
21+
- 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ] || [ "${TRAVIS_NODE_VERSION}" = "0.9" ]; then nvm install --latest-npm 0.8 && npm install && nvm use "${TRAVIS_NODE_VERSION}"; else npm install; fi;'
22+
script:
23+
- 'if [ -n "${PRETEST-}" ]; then npm run pretest ; fi'
24+
- 'if [ -n "${TEST-}" ]; then npm run tests-only ; fi'
25+
sudo: false
26+
env:
27+
- TEST=true
28+
matrix:
29+
fast_finish: true
30+
include:
31+
- node_js: "lts/*"
32+
env: PRETEST=true
33+
allow_failures:
34+
- os: osx
35+
- node_js: "0.12"
36+
- node_js: "0.10"

__tests__/src/getPropValue-test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
/* eslint-env mocha */
22
/* eslint no-template-curly-in-string: 0 */
33
import assert from 'assert';
4-
import { extractProp, changePlugins, fallbackToBabylon, describeIfNotBabylon } from '../helper';
4+
import {
5+
extractProp,
6+
changePlugins,
7+
fallbackToBabylon,
8+
describeIfNotBabylon,
9+
} from '../helper';
510
import getPropValue from '../../src/getPropValue';
611

712
describe('getPropValue', () => {

package.json

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,34 @@
44
"description": "AST utility module for statically analyzing JSX",
55
"main": "lib/index.js",
66
"scripts": {
7-
"build": "rimraf lib && babel src --out-dir lib",
8-
"prepublish": "npm run lint && npm run test && npm run build",
7+
"prebuild": "rimraf lib",
8+
"build": "babel src --out-dir lib",
9+
"prepublish": "not-in-publish || (npm test && npm run build)",
910
"coveralls": "cat ./reports/lcov.info | coveralls",
10-
"lint": "eslint --config .eslintrc .",
11-
"lint:fix": "npm run lint -- --fix",
11+
"lint": "eslint .",
1212
"pretest": "npm run lint",
13-
"test": "jest --coverage",
13+
"test": "npm run tests-only --",
14+
"tests-only": "jest --coverage",
1415
"test:watch": "npm test -- --watch"
1516
},
1617
"devDependencies": {
17-
"@babel/parser": "^7.3.2",
18-
"babel-cli": "^6.14.0",
19-
"babel-core": "^6.14.0",
20-
"babel-eslint": "^7.0.0",
21-
"babel-jest": "^20.0.0",
22-
"babel-polyfill": "^6.16.0",
23-
"babel-preset-es2015": "^6.14.0",
24-
"babylon": "^6.17.2",
25-
"coveralls": "^2.11.8",
26-
"eslint": "^3.12.1",
27-
"eslint-config-airbnb-base": "^11.1.0",
28-
"eslint-plugin-import": "^2.2.0",
29-
"jest": "^20.0.0",
18+
"@babel/parser": "^7.4.4",
19+
"babel-cli": "^6.26.0",
20+
"babel-core": "^6.26.3",
21+
"babel-eslint": "^7.2.3",
22+
"babel-jest": "^20.0.3",
23+
"babel-plugin-transform-replace-object-assign": "^1.0.0",
24+
"babel-polyfill": "^6.26.0",
25+
"babel-preset-env": "^1.7.0",
26+
"babylon": "^6.18.0",
27+
"coveralls": "^2.13.3",
28+
"eslint": "^5.16.0",
29+
"eslint-config-airbnb-base": "^13.1.0",
30+
"eslint-plugin-import": "^2.17.2",
31+
"in-publish": "^2.0.0",
32+
"jest": "^20.0.4",
3033
"jest-cli": "^20.0.4",
31-
"rimraf": "^2.5.2"
34+
"rimraf": "^2.6.3"
3235
},
3336
"engines": {
3437
"node": ">=4.0"
@@ -56,6 +59,7 @@
5659
]
5760
},
5861
"dependencies": {
59-
"array-includes": "^3.0.3"
62+
"array-includes": "^3.0.3",
63+
"object.assign": "^4.1.0"
6064
}
6165
}

src/values/expressions/ObjectExpression.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import assign from 'object.assign';
2+
13
/**
24
* Extractor function for an ObjectExpression type value node.
35
* An object expression is using {}.
@@ -12,7 +14,7 @@ export default function extractValueFromObjectExpression(value) {
1214
// Support types: SpreadProperty and ExperimentalSpreadProperty
1315
if (/^(?:Experimental)?Spread(?:Property|Element)$/.test(property.type)) {
1416
if (property.argument.type === 'ObjectExpression') {
15-
return Object.assign(object, extractValueFromObjectExpression(property.argument));
17+
return assign(object, extractValueFromObjectExpression(property.argument));
1618
}
1719
} else {
1820
object[getValue(property.key)] = getValue(property.value);

src/values/expressions/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ export default function extract(value) {
7373
let { type } = expression;
7474

7575
while (type === 'TSNonNullExpression' || type === 'TSAsExpression') {
76-
expression = expression.expression;
77-
type = expression.type;
76+
({ type } = expression);
77+
if (expression.expression) {
78+
({ expression } = expression);
79+
}
7880
}
7981

8082
if (TYPES[type] === undefined) {

0 commit comments

Comments
 (0)