i18next-parser
Advanced tools
Comparing version 1.0.0-beta22 to 1.0.0-beta23
@@ -1,7 +0,13 @@ | ||
"use strict";Object.defineProperty(exports, "__esModule", { value: true });var _extends = Object.assign || function (target) {for (var i = 1; i < arguments.length; i++) {var source = arguments[i];for (var key in source) {if (Object.prototype.hasOwnProperty.call(source, key)) {target[key] = source[key];}}}return target;};var _createClass = function () {function defineProperties(target, props) {for (var i = 0; i < props.length; i++) {var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);}}return function (Constructor, protoProps, staticProps) {if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;};}();var _acornJsx = require("acorn-jsx");var acorn = _interopRequireWildcard(_acornJsx); | ||
var _inject = require("acorn-object-rest-spread/inject");var _inject2 = _interopRequireDefault(_inject); | ||
"use strict";Object.defineProperty(exports, "__esModule", { value: true });var _extends = Object.assign || function (target) {for (var i = 1; i < arguments.length; i++) {var source = arguments[i];for (var key in source) {if (Object.prototype.hasOwnProperty.call(source, key)) {target[key] = source[key];}}}return target;};var _createClass = function () {function defineProperties(target, props) {for (var i = 0; i < props.length; i++) {var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);}}return function (Constructor, protoProps, staticProps) {if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;};}();var _acorn = require("acorn");var acorn = _interopRequireWildcard(_acorn); | ||
var _inject = require("acorn-stage3/inject");var _inject2 = _interopRequireDefault(_inject); | ||
var _acornEs = require("acorn-es7");var _acornEs2 = _interopRequireDefault(_acornEs); | ||
var _walk = require("acorn/dist/walk");var walk = _interopRequireWildcard(_walk); | ||
var _baseLexer = require("./base-lexer");var _baseLexer2 = _interopRequireDefault(_baseLexer);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function _interopRequireWildcard(obj) {if (obj && obj.__esModule) {return obj;} else {var newObj = {};if (obj != null) {for (var key in obj) {if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key];}}newObj.default = obj;return newObj;}}function _classCallCheck(instance, Constructor) {if (!(instance instanceof Constructor)) {throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self, call) {if (!self) {throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call && (typeof call === "object" || typeof call === "function") ? call : self;}function _inherits(subClass, superClass) {if (typeof superClass !== "function" && superClass !== null) {throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;}var | ||
var _baseLexer = require("./base-lexer");var _baseLexer2 = _interopRequireDefault(_baseLexer);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function _interopRequireWildcard(obj) {if (obj && obj.__esModule) {return obj;} else {var newObj = {};if (obj != null) {for (var key in obj) {if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key];}}newObj.default = obj;return newObj;}}function _classCallCheck(instance, Constructor) {if (!(instance instanceof Constructor)) {throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self, call) {if (!self) {throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call && (typeof call === "object" || typeof call === "function") ? call : self;}function _inherits(subClass, superClass) {if (typeof superClass !== "function" && superClass !== null) {throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;} | ||
var WalkerBase = Object.assign({}, walk.base, { | ||
Import: function Import(node, st, c) { | ||
// We need this catch, but we don't need the catch to do anything. | ||
} });var | ||
JavascriptLexer = function (_BaseLexer) {_inherits(JavascriptLexer, _BaseLexer); | ||
@@ -11,5 +17,27 @@ function JavascriptLexer() {var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};_classCallCheck(this, JavascriptLexer);var _this = _possibleConstructorReturn(this, (JavascriptLexer.__proto__ || Object.getPrototypeOf(JavascriptLexer)).call(this, | ||
_this.acornOptions = _extends({ sourceType: 'module' }, options.acorn); | ||
_this.acornOptions = _extends({ | ||
sourceType: 'module', | ||
ecmaVersion: 9 }, | ||
options.acorn, { | ||
plugins: _extends({ | ||
stage3: true, | ||
es7: true }, | ||
options.acorn ? options.acorn.plugins : {}) }); | ||
_this.functions = options.functions || ['t']; | ||
_this.attr = options.attr || 'i18nKey';return _this; | ||
_this.attr = options.attr || 'i18nKey'; | ||
_this.acorn = acorn; | ||
_this.WalkerBase = WalkerBase; | ||
if (_this.acornOptions.plugins) { | ||
if (_this.acornOptions.plugins.stage3) { | ||
_this.acorn = (0, _inject2.default)(_this.acorn); | ||
} | ||
if (_this.acornOptions.plugins.es7) { | ||
(0, _acornEs2.default)(_this.acorn); | ||
} | ||
}return _this; | ||
}_createClass(JavascriptLexer, [{ key: "extract", value: function extract( | ||
@@ -20,20 +48,10 @@ | ||
var localAcorn = acorn; | ||
if (this.acornOptions.plugins) { | ||
if (this.acornOptions.plugins.es7) { | ||
(0, _acornEs2.default)(localAcorn); | ||
} | ||
if (this.acornOptions.plugins.objectRestSpread) { | ||
(0, _inject2.default)(localAcorn); | ||
} | ||
} | ||
walk.simple( | ||
localAcorn.parse(content, this.acornOptions), | ||
this.acorn.parse(content, this.acornOptions), | ||
{ | ||
CallExpression: function CallExpression(node) { | ||
that.expressionExtractor.call(that, node); | ||
} }); | ||
} }, | ||
this.WalkerBase); | ||
@@ -40,0 +58,0 @@ |
@@ -1,6 +0,6 @@ | ||
'use strict';Object.defineProperty(exports, "__esModule", { value: true });var _extends = Object.assign || function (target) {for (var i = 1; i < arguments.length; i++) {var source = arguments[i];for (var key in source) {if (Object.prototype.hasOwnProperty.call(source, key)) {target[key] = source[key];}}}return target;};var _createClass = function () {function defineProperties(target, props) {for (var i = 0; i < props.length; i++) {var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);}}return function (Constructor, protoProps, staticProps) {if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;};}();var _acornJsx = require('acorn-jsx');var acorn = _interopRequireWildcard(_acornJsx); | ||
'use strict';Object.defineProperty(exports, "__esModule", { value: true });var _extends = Object.assign || function (target) {for (var i = 1; i < arguments.length; i++) {var source = arguments[i];for (var key in source) {if (Object.prototype.hasOwnProperty.call(source, key)) {target[key] = source[key];}}}return target;};var _createClass = function () {function defineProperties(target, props) {for (var i = 0; i < props.length; i++) {var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);}}return function (Constructor, protoProps, staticProps) {if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;};}();var _javascriptLexer = require('./javascript-lexer');var _javascriptLexer2 = _interopRequireDefault(_javascriptLexer); | ||
var _walk = require('acorn/dist/walk');var walk = _interopRequireWildcard(_walk); | ||
var _javascriptLexer = require('./javascript-lexer');var _javascriptLexer2 = _interopRequireDefault(_javascriptLexer);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function _interopRequireWildcard(obj) {if (obj && obj.__esModule) {return obj;} else {var newObj = {};if (obj != null) {for (var key in obj) {if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key];}}newObj.default = obj;return newObj;}}function _classCallCheck(instance, Constructor) {if (!(instance instanceof Constructor)) {throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self, call) {if (!self) {throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call && (typeof call === "object" || typeof call === "function") ? call : self;}function _inherits(subClass, superClass) {if (typeof superClass !== "function" && superClass !== null) {throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;} | ||
var _inject = require('acorn-jsx/inject');var _inject2 = _interopRequireDefault(_inject);function _interopRequireWildcard(obj) {if (obj && obj.__esModule) {return obj;} else {var newObj = {};if (obj != null) {for (var key in obj) {if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key];}}newObj.default = obj;return newObj;}}function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function _classCallCheck(instance, Constructor) {if (!(instance instanceof Constructor)) {throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self, call) {if (!self) {throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call && (typeof call === "object" || typeof call === "function") ? call : self;}function _inherits(subClass, superClass) {if (typeof superClass !== "function" && superClass !== null) {throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;} | ||
var JSXParserExtension = Object.assign({}, walk.base, { | ||
var JSXParserExtension = { | ||
JSXText: function JSXText(node, st, c) { | ||
@@ -26,10 +26,16 @@ // We need this catch, but we don't need the catch to do anything. | ||
c(node.argument, st, node.argument.type); | ||
} });var | ||
} };var | ||
JsxLexer = function (_JavascriptLexer) {_inherits(JsxLexer, _JavascriptLexer); | ||
function JsxLexer() {var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};_classCallCheck(this, JsxLexer);var _this = _possibleConstructorReturn(this, (JsxLexer.__proto__ || Object.getPrototypeOf(JsxLexer)).call(this, | ||
options)); | ||
function JsxLexer() {var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};_classCallCheck(this, JsxLexer); | ||
_this.acornOptions = _extends({ sourceType: 'module', plugins: { jsx: true } }, options.acorn);return _this; | ||
// super will setup acornOptions, acorn and the walker, just add what we need | ||
var _this = _possibleConstructorReturn(this, (JsxLexer.__proto__ || Object.getPrototypeOf(JsxLexer)).call(this, options));_this.acornOptions.plugins.jsx = true; | ||
_this.WalkerBase = Object.assign({}, _this.WalkerBase, _extends({}, | ||
JSXParserExtension)); | ||
_this.acorn = (0, _inject2.default)(_this.acorn);return _this; | ||
}_createClass(JsxLexer, [{ key: 'extract', value: function extract( | ||
@@ -41,3 +47,3 @@ | ||
walk.simple( | ||
acorn.parse(content, this.acornOptions), | ||
this.acorn.parse(content, this.acornOptions), | ||
{ | ||
@@ -84,3 +90,3 @@ CallExpression: function CallExpression(node) { | ||
JSXParserExtension); | ||
this.WalkerBase); | ||
@@ -87,0 +93,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"name": "i18next-parser", | ||
"version": "1.0.0-beta22", | ||
"version": "1.0.0-beta23", | ||
"license": "MIT", | ||
@@ -24,3 +24,3 @@ "main": "dist/index.js", | ||
"acorn-jsx": "^4.1.1", | ||
"acorn-object-rest-spread": "^1.1.0", | ||
"acorn-stage3": "^0.6.0", | ||
"broccoli-plugin": "^1.3.0", | ||
@@ -27,0 +27,0 @@ "cheerio": "^1.0.0-rc.2", |
@@ -1,3 +0,3 @@ | ||
import * as acorn from 'acorn-jsx' | ||
import injectAcornObjectRestSpread from "acorn-object-rest-spread/inject" | ||
import * as acorn from 'acorn' | ||
import injectAcornStage3 from "acorn-stage3/inject" | ||
import injectAcornEs7 from "acorn-es7" | ||
@@ -7,2 +7,8 @@ import * as walk from 'acorn/dist/walk' | ||
const WalkerBase = Object.assign({}, walk.base, { | ||
Import(node, st, c) { | ||
// We need this catch, but we don't need the catch to do anything. | ||
} | ||
}) | ||
export default class JavascriptLexer extends BaseLexer { | ||
@@ -12,23 +18,34 @@ constructor(options = {}) { | ||
this.acornOptions = { sourceType: 'module', ...options.acorn } | ||
this.acornOptions = { | ||
sourceType: 'module', | ||
ecmaVersion: 9, | ||
...options.acorn, | ||
plugins: { | ||
stage3: true, | ||
es7: true, | ||
...(options.acorn ? options.acorn.plugins : {}) | ||
} | ||
} | ||
this.functions = options.functions || ['t'] | ||
this.attr = options.attr || 'i18nKey' | ||
} | ||
extract(content) { | ||
const that = this | ||
this.acorn = acorn | ||
this.WalkerBase = WalkerBase | ||
let localAcorn = acorn | ||
if (this.acornOptions.plugins) { | ||
if (this.acornOptions.plugins.stage3) { | ||
this.acorn = injectAcornStage3(this.acorn) | ||
} | ||
if (this.acornOptions.plugins.es7) { | ||
injectAcornEs7(localAcorn) | ||
injectAcornEs7(this.acorn) | ||
} | ||
if (this.acornOptions.plugins.objectRestSpread) { | ||
injectAcornObjectRestSpread(localAcorn) | ||
} | ||
} | ||
} | ||
extract(content) { | ||
const that = this | ||
walk.simple( | ||
localAcorn.parse(content, this.acornOptions), | ||
this.acorn.parse(content, this.acornOptions), | ||
{ | ||
@@ -38,3 +55,4 @@ CallExpression(node) { | ||
} | ||
} | ||
}, | ||
this.WalkerBase | ||
) | ||
@@ -41,0 +59,0 @@ |
@@ -1,6 +0,6 @@ | ||
import * as acorn from 'acorn-jsx' | ||
import JavascriptLexer from './javascript-lexer' | ||
import * as walk from 'acorn/dist/walk' | ||
import JavascriptLexer from './javascript-lexer' | ||
import injectAcornJsx from 'acorn-jsx/inject' | ||
const JSXParserExtension = Object.assign({}, walk.base, { | ||
const JSXParserExtension = { | ||
JSXText(node, st, c) { | ||
@@ -27,3 +27,3 @@ // We need this catch, but we don't need the catch to do anything. | ||
} | ||
}) | ||
} | ||
@@ -34,3 +34,9 @@ export default class JsxLexer extends JavascriptLexer { | ||
this.acornOptions = { sourceType: 'module', plugins: { jsx: true }, ...options.acorn } | ||
// super will setup acornOptions, acorn and the walker, just add what we need | ||
this.acornOptions.plugins.jsx = true | ||
this.WalkerBase = Object.assign({}, this.WalkerBase, { | ||
...JSXParserExtension | ||
}) | ||
this.acorn = injectAcornJsx(this.acorn) | ||
} | ||
@@ -42,3 +48,3 @@ | ||
walk.simple( | ||
acorn.parse(content, this.acornOptions), | ||
this.acorn.parse(content, this.acornOptions), | ||
{ | ||
@@ -85,3 +91,3 @@ CallExpression(node) { | ||
}, | ||
JSXParserExtension | ||
this.WalkerBase | ||
) | ||
@@ -88,0 +94,0 @@ |
@@ -88,2 +88,9 @@ import { assert } from 'chai' | ||
it('supports async/await', (done) => { | ||
const Lexer = new JavascriptLexer({ acorn: { ecmaVersion: 8 } }) | ||
const content = 'const data = async () => await Promise.resolve()' | ||
Lexer.extract(content) | ||
done() | ||
}) | ||
it('supports the acorn-es7 plugin', (done) => { | ||
@@ -98,4 +105,4 @@ const Lexer = new JavascriptLexer({ acorn: { plugins: { es7: true } } }) | ||
it('supports the acorn-object-rest-spread plugin', (done) => { | ||
const Lexer = new JavascriptLexer({ acorn: { plugins: { objectRestSpread: true } } }) | ||
it('supports the spread operator in objects plugin', (done) => { | ||
const Lexer = new JavascriptLexer({ acorn: { ecmaVersion: 9 } }) | ||
const content = 'const data = { text: t("foo"), ...rest }; const { text, ...more } = data;' | ||
@@ -108,2 +115,12 @@ assert.deepEqual(Lexer.extract(content), [ | ||
describe('supports the acorn-stage3 plugin', () => { | ||
it('supports dynamic imports', (done) => { | ||
const Lexer = new JavascriptLexer({ acorn: { ecmaVersion: 6, plugins: { stage3: true } } }) | ||
const content = 'import("path/to/some/file").then(doSomethingWithData)' | ||
Lexer.extract(content) | ||
done() | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
458772
3746
+ Addedacorn-stage3@^0.6.0
+ Addedacorn-bigint@0.2.0(transitive)
+ Addedacorn-class-fields@0.1.2(transitive)
+ Addedacorn-dynamic-import@3.0.0(transitive)
+ Addedacorn-import-meta@0.2.1(transitive)
+ Addedacorn-json-superset@0.1.1(transitive)
+ Addedacorn-numeric-separator@0.1.1(transitive)
+ Addedacorn-optional-catch-binding@0.1.1(transitive)
+ Addedacorn-private-methods@0.1.1(transitive)
+ Addedacorn-stage3@0.6.0(transitive)
- Removedacorn-object-rest-spread@^1.1.0
- Removedacorn-object-rest-spread@1.1.0(transitive)