jsx-ast-utils
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -40,1 +40,3 @@ /* eslint-env jest */ | ||
} | ||
export const describeIfNotBabylon = fallbackToBabylon ? describe.skip : describe; |
/* eslint-env mocha */ | ||
/* eslint no-template-curly-in-string: 0 */ | ||
import assert from 'assert'; | ||
import { extractProp } from '../helper'; | ||
import { extractProp, describeIfNotBabylon, changePlugins } from '../helper'; | ||
import { getLiteralPropValue } from '../../src/getPropValue'; | ||
@@ -22,3 +22,3 @@ | ||
it('should throw error when trying to get value from unknown node type', () => { | ||
it('should not throw error when trying to get value from unknown node type', () => { | ||
const prop = { | ||
@@ -31,5 +31,7 @@ type: 'JSXAttribute', | ||
assert.throws(() => { | ||
assert.doesNotThrow(() => { | ||
getLiteralPropValue(prop); | ||
}, Error); | ||
assert.equal(null, getLiteralPropValue(prop)); | ||
}); | ||
@@ -470,2 +472,36 @@ | ||
}); | ||
describeIfNotBabylon('Typescript', () => { | ||
beforeEach(() => { | ||
changePlugins(pls => [...pls, 'typescript']); | ||
}); | ||
it('should return string representation of variable identifier wrapped in a Typescript non-null assertion', () => { | ||
const prop = extractProp('<div foo={bar!} />'); | ||
const expected = null; | ||
const actual = getLiteralPropValue(prop); | ||
assert.equal(expected, actual); | ||
}); | ||
it('should return string representation of variable identifier wrapped in a deep Typescript non-null assertion', () => { | ||
const prop = extractProp('<div foo={(bar!)!} />'); | ||
const expected = null; | ||
const actual = getLiteralPropValue(prop); | ||
assert.equal(expected, actual); | ||
}); | ||
it('should return string representation of variable identifier wrapped in a Typescript type coercion', () => { | ||
changePlugins(pls => [...pls, 'typescript']); | ||
const prop = extractProp('<div foo={bar as any} />'); | ||
const expected = null; | ||
const actual = getLiteralPropValue(prop); | ||
assert.equal(expected, actual); | ||
}); | ||
}); | ||
}); |
/* eslint-env mocha */ | ||
/* eslint no-template-curly-in-string: 0 */ | ||
import assert from 'assert'; | ||
import { extractProp, changePlugins, fallbackToBabylon } from '../helper'; | ||
import { | ||
extractProp, | ||
changePlugins, | ||
fallbackToBabylon, | ||
describeIfNotBabylon, | ||
} from '../helper'; | ||
import getPropValue from '../../src/getPropValue'; | ||
const describeIfNotBabylon = fallbackToBabylon ? describe.skip : describe; | ||
describe('getPropValue', () => { | ||
@@ -32,5 +35,7 @@ it('should export a function', () => { | ||
assert.throws(() => { | ||
assert.doesNotThrow(() => { | ||
getPropValue(prop); | ||
}, Error); | ||
assert.equal(null, getPropValue(prop)); | ||
}); | ||
@@ -37,0 +42,0 @@ |
@@ -0,1 +1,17 @@ | ||
2.2.0 / 2019-06-25 | ||
================== | ||
- (fix) Fix getLiteralPropValue for TS-specific node types. | ||
- (chore) upgrade dependencies. | ||
- (improvement) Stop throwing errors when unknown AST nodes are encountered. | ||
- (dev) CI changes. | ||
2.1.0 / 2018-04-19 | ||
================== | ||
- Fix undefined bug for template strings. #45 | ||
- Adding support for `objectRestSpread` within props #60 | ||
- Accommodate ExperimentalSpreadProperty in prop values #75 | ||
- Account for SpreadElement AST Nodes #76 | ||
- Support OptionalMemberExpression AST nodes #77 | ||
- Add support to Typescript's node types #72 | ||
2.0.1 / 2017-08-31 | ||
@@ -2,0 +18,0 @@ ================== |
@@ -9,2 +9,6 @@ 'use strict'; | ||
var _object = require('object.assign'); | ||
var _object2 = _interopRequireDefault(_object); | ||
var _Literal = require('../Literal'); | ||
@@ -149,8 +153,15 @@ | ||
while (type === 'TSNonNullExpression' || type === 'TSAsExpression') { | ||
expression = expression.expression; | ||
type = expression.type; | ||
var _expression2 = expression; | ||
type = _expression2.type; | ||
if (expression.expression) { | ||
var _expression3 = expression; | ||
expression = _expression3.expression; | ||
} | ||
} | ||
if (TYPES[type] === undefined) { | ||
throw new Error(errorMessage(type)); | ||
// eslint-disable-next-line no-console | ||
console.error(errorMessage(type)); | ||
return null; | ||
} | ||
@@ -162,3 +173,3 @@ | ||
// Composition map of types to their extractor functions to handle literals. | ||
var LITERAL_TYPES = Object.assign({}, TYPES, { | ||
var LITERAL_TYPES = (0, _object2.default)({}, TYPES, { | ||
Literal: function Literal(value) { | ||
@@ -202,3 +213,5 @@ var extractedVal = TYPES.Literal.call(undefined, value); | ||
BindExpression: noop, | ||
SpreadElement: noop | ||
SpreadElement: noop, | ||
TSNonNullExpression: noop, | ||
TSAsExpression: noop | ||
}); | ||
@@ -223,3 +236,5 @@ | ||
if (LITERAL_TYPES[type] === undefined) { | ||
throw new Error(errorMessage(type)); | ||
// eslint-disable-next-line no-console | ||
console.error(errorMessage(type)); | ||
return null; | ||
} | ||
@@ -226,0 +241,0 @@ |
@@ -7,2 +7,9 @@ 'use strict'; | ||
exports.default = extractValueFromObjectExpression; | ||
var _object = require('object.assign'); | ||
var _object2 = _interopRequireDefault(_object); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
@@ -18,7 +25,7 @@ * Extractor function for an ObjectExpression type value node. | ||
return value.properties.reduce(function (obj, property) { | ||
var object = Object.assign({}, obj); | ||
var object = (0, _object2.default)({}, obj); | ||
// Support types: SpreadProperty and ExperimentalSpreadProperty | ||
if (/^(?:Experimental)?Spread(?:Property|Element)$/.test(property.type)) { | ||
if (property.argument.type === 'ObjectExpression') { | ||
return Object.assign(object, extractValueFromObjectExpression(property.argument)); | ||
return (0, _object2.default)(object, extractValueFromObjectExpression(property.argument)); | ||
} | ||
@@ -25,0 +32,0 @@ } else { |
@@ -9,2 +9,6 @@ 'use strict'; | ||
var _object = require('object.assign'); | ||
var _object2 = _interopRequireDefault(_object); | ||
var _Literal = require('./Literal'); | ||
@@ -32,3 +36,3 @@ | ||
// Composition map of types to their extractor functions to handle literals. | ||
var LITERAL_TYPES = Object.assign({}, TYPES, { | ||
var LITERAL_TYPES = (0, _object2.default)({}, TYPES, { | ||
JSXElement: function JSXElement() { | ||
@@ -35,0 +39,0 @@ return null; |
{ | ||
"name": "jsx-ast-utils", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "AST utility module for statically analyzing JSX", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"build": "rimraf lib && babel src --out-dir lib", | ||
"prepublish": "npm run lint && npm run test && npm run build", | ||
"prebuild": "rimraf lib", | ||
"build": "babel src --out-dir lib", | ||
"prepublish": "not-in-publish || (npm test && npm run build)", | ||
"coveralls": "cat ./reports/lcov.info | coveralls", | ||
"lint": "eslint --config .eslintrc .", | ||
"lint:fix": "npm run lint -- --fix", | ||
"lint": "eslint .", | ||
"pretest": "npm run lint", | ||
"test": "jest --coverage", | ||
"test": "npm run tests-only --", | ||
"tests-only": "jest --coverage", | ||
"test:watch": "npm test -- --watch" | ||
}, | ||
"devDependencies": { | ||
"@babel/parser": "^7.3.2", | ||
"babel-cli": "^6.14.0", | ||
"babel-core": "^6.14.0", | ||
"babel-eslint": "^7.0.0", | ||
"babel-jest": "^20.0.0", | ||
"babel-polyfill": "^6.16.0", | ||
"babel-preset-es2015": "^6.14.0", | ||
"babylon": "^6.17.2", | ||
"coveralls": "^2.11.8", | ||
"eslint": "^3.12.1", | ||
"eslint-config-airbnb-base": "^11.1.0", | ||
"eslint-plugin-import": "^2.2.0", | ||
"jest": "^20.0.0", | ||
"@babel/parser": "^7.4.4", | ||
"babel-cli": "^6.26.0", | ||
"babel-core": "^6.26.3", | ||
"babel-eslint": "^10.0.2", | ||
"babel-jest": "^20.0.3", | ||
"babel-plugin-transform-replace-object-assign": "^1.0.0", | ||
"babel-polyfill": "^6.26.0", | ||
"babel-preset-env": "^1.7.0", | ||
"babylon": "^6.18.0", | ||
"coveralls": "^3.0.4", | ||
"eslint": "^6.0.0", | ||
"eslint-config-airbnb-base": "^13.1.0", | ||
"eslint-plugin-import": "^2.17.2", | ||
"in-publish": "^2.0.0", | ||
"jest": "^20.0.4", | ||
"jest-cli": "^20.0.4", | ||
"rimraf": "^2.5.2" | ||
"rimraf": "^2.6.3" | ||
}, | ||
@@ -59,4 +62,5 @@ "engines": { | ||
"dependencies": { | ||
"array-includes": "^3.0.3" | ||
"array-includes": "^3.0.3", | ||
"object.assign": "^4.1.0" | ||
} | ||
} |
@@ -76,8 +76,12 @@ import Literal from '../Literal'; | ||
while (type === 'TSNonNullExpression' || type === 'TSAsExpression') { | ||
expression = expression.expression; | ||
type = expression.type; | ||
({ type } = expression); | ||
if (expression.expression) { | ||
({ expression } = expression); | ||
} | ||
} | ||
if (TYPES[type] === undefined) { | ||
throw new Error(errorMessage(type)); | ||
// eslint-disable-next-line no-console | ||
console.error(errorMessage(type)); | ||
return null; | ||
} | ||
@@ -127,2 +131,4 @@ | ||
SpreadElement: noop, | ||
TSNonNullExpression: noop, | ||
TSAsExpression: noop, | ||
}); | ||
@@ -146,3 +152,5 @@ | ||
if (LITERAL_TYPES[type] === undefined) { | ||
throw new Error(errorMessage(type)); | ||
// eslint-disable-next-line no-console | ||
console.error(errorMessage(type)); | ||
return null; | ||
} | ||
@@ -149,0 +157,0 @@ |
@@ -0,1 +1,3 @@ | ||
import assign from 'object.assign'; | ||
/** | ||
@@ -15,3 +17,3 @@ * Extractor function for an ObjectExpression type value node. | ||
if (property.argument.type === 'ObjectExpression') { | ||
return Object.assign(object, extractValueFromObjectExpression(property.argument)); | ||
return assign(object, extractValueFromObjectExpression(property.argument)); | ||
} | ||
@@ -18,0 +20,0 @@ } else { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
138568
3386
2
17
+ Addedobject.assign@^4.1.0