@hqjs/babel-plugin-transform-json-imports
Advanced tools
Comparing version 0.0.1 to 0.0.2
11
index.js
@@ -12,3 +12,3 @@ const fs = require('fs'); | ||
const notRequire = (t, nodePath) => { | ||
const [ requireArg, ...rest ] = nodePath.node.arguments; | ||
const [requireArg, ...rest] = nodePath.node.arguments; | ||
return nodePath.node.callee.name !== 'require' || | ||
@@ -20,3 +20,3 @@ rest.length !== 0 || | ||
module.exports = function({ types: t }) { | ||
module.exports = function ({ types: t }) { | ||
return { | ||
@@ -27,3 +27,3 @@ visitor: { | ||
if (notRequire(t, nodePath)) return; | ||
const [ requireArg ] = nodePath.node.arguments; | ||
const [requireArg] = nodePath.node.arguments; | ||
const { value: modName } = requireArg; | ||
@@ -64,3 +64,3 @@ if (notJsonImport(modName)) return; | ||
const [ specifier ] = node.specifiers; | ||
const [specifier] = node.specifiers; | ||
@@ -71,4 +71,3 @@ return t.identifier(specifier.local.name); | ||
function isDestructuredImportExpression(t, node) { | ||
const [ specifier, ...rest ] = node.specifiers; | ||
return rest.length !== 0 || t.isImportDefaultSpecifier(specifier); | ||
return node.specifiers.length !== 0 && node.specifiers.some(specifier => !t.isImportDefaultSpecifier(specifier)); | ||
} | ||
@@ -75,0 +74,0 @@ |
{ | ||
"name": "@hqjs/babel-plugin-transform-json-imports", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Transform json imports", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -8,1 +8,23 @@ # https://hqjs.org | ||
``` | ||
# Transformation | ||
Transforms `.json` imports into inplace definition e.g. having file values.json | ||
```json | ||
{ | ||
"a": 1, | ||
"b": 2 | ||
} | ||
``` | ||
and importing it | ||
```js | ||
import values from './values.json'; | ||
// Or with destructure | ||
import {a, b} from './values.json'; | ||
``` | ||
we will obtain | ||
```js | ||
const values = {a: 1, b: 2}; | ||
const {a, b} = {a: 1, b: 2}; | ||
``` |
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
13003
30
61