jsx-ast-utils
Advanced tools
Comparing version 3.1.0 to 3.2.0
@@ -74,3 +74,4 @@ /* eslint-env jest */ | ||
if (Array.isArray(body) && body[0] != null) { | ||
return body[0].expression.openingElement; | ||
const [{ expression }] = body; | ||
return expression.type === 'JSXFragment' ? expression.openingFragment : expression.openingElement; | ||
} | ||
@@ -77,0 +78,0 @@ |
@@ -85,2 +85,12 @@ /* eslint-env mocha */ | ||
}); | ||
it('should work with fragments', () => { | ||
const code = '<>foo</>'; | ||
const node = getOpeningElement(code); | ||
const expected = '<>'; | ||
const actual = elementType(node); | ||
assert.equal(actual, expected); | ||
}); | ||
}); |
@@ -521,3 +521,10 @@ /* eslint-env mocha */ | ||
}); | ||
it('should work with a this.props value', () => { | ||
const prop = extractProp('<a href={this.props.href!}>Download</a>'); | ||
const expected = null; | ||
const actual = getLiteralPropValue(prop); | ||
assert.equal(actual, expected); | ||
}); | ||
}); | ||
}); |
@@ -17,2 +17,3 @@ /* eslint-env mocha */ | ||
}); | ||
it('should export a function', () => { | ||
@@ -1178,3 +1179,19 @@ const expected = 'function'; | ||
}); | ||
it('should work with a this.props value', () => { | ||
const prop = extractProp('<a foo={this.props.href!}>Download</a>'); | ||
const expected = 'this.props.href!'; | ||
const actual = getPropValue(prop); | ||
assert.equal(actual, expected); | ||
}); | ||
}); | ||
describe('JSX empty expression', () => { | ||
it('should work with an empty expression', () => { | ||
const prop = extractProp('<div>\n{/* Hello there */}\n</div>', 'children'); | ||
const expected = undefined; | ||
const actual = getPropValue(prop); | ||
assert.equal(actual, expected); | ||
}); | ||
}); | ||
}); |
@@ -16,2 +16,3 @@ /* eslint-env mocha */ | ||
}); | ||
it('should export a function', () => { | ||
@@ -954,2 +955,11 @@ const expected = 'function'; | ||
}); | ||
describe('JSX empty expression', () => { | ||
it('should work with an empty expression', () => { | ||
const prop = extractProp('<div>\n{/* Hello there */}\n</div>', 'children'); | ||
const expected = undefined; | ||
const actual = getPropValue(prop); | ||
assert.equal(actual, expected); | ||
}); | ||
}); | ||
}); |
Unreleased | ||
================== | ||
3.2.0 / 2020-12-16 | ||
================== | ||
- [New] add support for fragment syntax (`<>`) (#108) | ||
- [Fix] `TSNonNullExpression`: handle `ThisExpression`s (#108) | ||
- [Deps] update `array-includes`, `object.assign` | ||
- [Dev Deps] update `@babel/core`, `@babel/parser`, `eslint`, `eslint-config-airbnb-base`, `object.entries`, `object.fromentries` | ||
3.1.0 / 2020-10-13 | ||
@@ -5,0 +12,0 @@ ================== |
@@ -26,2 +26,6 @@ 'use strict'; | ||
if (node.type === 'JSXOpeningFragment') { | ||
return '<>'; | ||
} | ||
if (!name) { | ||
@@ -28,0 +32,0 @@ throw new Error('The argument provided is not a JSXElement node.'); |
@@ -7,2 +7,4 @@ 'use strict'; | ||
exports.default = extractValueFromTSNonNullExpression; | ||
var extractValueFromThisExpression = require('./ThisExpression').default; | ||
/** | ||
@@ -29,2 +31,6 @@ * Extractor function for a TSNonNullExpression type value node. | ||
if (value.type === 'ThisExpression') { | ||
return extractValueFromThisExpression(); | ||
} | ||
// does not contains properties & is not parenthesized | ||
@@ -31,0 +37,0 @@ if (value.type === 'TSNonNullExpression' && (!value.extra || value.extra.parenthesized === false)) { |
{ | ||
"name": "jsx-ast-utils", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "AST utility module for statically analyzing JSX", | ||
@@ -18,4 +18,4 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@babel/core": "^7.11.6", | ||
"@babel/parser": "^7.11.5", | ||
"@babel/core": "^7.12.10", | ||
"@babel/parser": "^7.12.11", | ||
"babel-cli": "^6.26.0", | ||
@@ -31,4 +31,4 @@ "babel-core": "^6.26.3", | ||
"coveralls": "^3.1.0", | ||
"eslint": "^7.11.0", | ||
"eslint-config-airbnb-base": "^14.2.0", | ||
"eslint": "^7.15.0", | ||
"eslint-config-airbnb-base": "^14.2.1", | ||
"eslint-plugin-import": "^2.22.1", | ||
@@ -39,4 +39,4 @@ "flow-parser": "^0.126.1", | ||
"jest-cli": "^20.0.4", | ||
"object.entries": "^1.1.2", | ||
"object.fromentries": "^2.0.2", | ||
"object.entries": "^1.1.3", | ||
"object.fromentries": "^2.0.3", | ||
"rimraf": "^2.7.1", | ||
@@ -71,5 +71,5 @@ "safe-publish-latest": "^1.1.4" | ||
"dependencies": { | ||
"array-includes": "^3.1.1", | ||
"object.assign": "^4.1.1" | ||
"array-includes": "^3.1.2", | ||
"object.assign": "^4.1.2" | ||
} | ||
} |
@@ -15,2 +15,6 @@ function resolveMemberExpressions(object = {}, property = {}) { | ||
if (node.type === 'JSXOpeningFragment') { | ||
return '<>'; | ||
} | ||
if (!name) { | ||
@@ -17,0 +21,0 @@ throw new Error('The argument provided is not a JSXElement node.'); |
@@ -0,1 +1,3 @@ | ||
const extractValueFromThisExpression = require('./ThisExpression').default; | ||
/** | ||
@@ -21,2 +23,6 @@ * Extractor function for a TSNonNullExpression type value node. | ||
if (value.type === 'ThisExpression') { | ||
return extractValueFromThisExpression(); | ||
} | ||
// does not contains properties & is not parenthesized | ||
@@ -23,0 +29,0 @@ if (value.type === 'TSNonNullExpression' && (!value.extra || value.extra.parenthesized === false)) { |
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
222471
5433
Updatedarray-includes@^3.1.2
Updatedobject.assign@^4.1.2