i18next-parser
Advanced tools
Comparing version 1.0.0-beta21 to 1.0.0-beta22
@@ -1,4 +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); | ||
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 | ||
"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); | ||
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 | ||
@@ -12,3 +14,3 @@ JavascriptLexer = function (_BaseLexer) {_inherits(JavascriptLexer, _BaseLexer); | ||
_this.attr = options.attr || 'i18nKey';return _this; | ||
}_createClass(JavascriptLexer, [{ key: 'extract', value: function extract( | ||
}_createClass(JavascriptLexer, [{ key: "extract", value: function extract( | ||
@@ -18,4 +20,15 @@ content) { | ||
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( | ||
acorn.parse(content, this.acornOptions), | ||
localAcorn.parse(content, this.acornOptions), | ||
{ | ||
@@ -29,3 +42,3 @@ CallExpression: function CallExpression(node) { | ||
return this.keys; | ||
} }, { key: 'expressionExtractor', value: function expressionExtractor( | ||
} }, { key: "expressionExtractor", value: function expressionExtractor( | ||
@@ -49,3 +62,3 @@ node) { | ||
if (!concatenatedString) { | ||
this.emit('warning', 'Key is not a string literal: ' + keyArgument.name); | ||
this.emit('warning', "Key is not a string literal: " + keyArgument.name); | ||
return; | ||
@@ -57,3 +70,3 @@ } | ||
if (keyArgument.type === 'Identifier') { | ||
this.emit('warning', 'Key is not a string literal: ' + keyArgument.name); | ||
this.emit('warning', "Key is not a string literal: " + keyArgument.name); | ||
} | ||
@@ -78,3 +91,3 @@ | ||
} | ||
} }, { key: 'concatenateString', value: function concatenateString( | ||
} }, { key: "concatenateString", value: function concatenateString( | ||
@@ -107,2 +120,2 @@ binaryExpression) {var string = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; | ||
return string; | ||
} }]);return JavascriptLexer;}(_baseLexer2.default);exports.default = JavascriptLexer;module.exports = exports['default']; | ||
} }]);return JavascriptLexer;}(_baseLexer2.default);exports.default = JavascriptLexer;module.exports = exports["default"]; |
@@ -5,3 +5,3 @@ { | ||
"name": "i18next-parser", | ||
"version": "1.0.0-beta21", | ||
"version": "1.0.0-beta22", | ||
"license": "MIT", | ||
@@ -22,3 +22,5 @@ "main": "dist/index.js", | ||
"acorn": "^5.5.3", | ||
"acorn-es7": "^0.1.0", | ||
"acorn-jsx": "^4.1.1", | ||
"acorn-object-rest-spread": "^1.1.0", | ||
"broccoli-plugin": "^1.3.0", | ||
@@ -25,0 +27,0 @@ "cheerio": "^1.0.0-rc.2", |
@@ -161,2 +161,14 @@ # i18next Parser [![Build Status](https://travis-ci.org/i18next/i18next-parser.svg?branch=master)](https://travis-ci.org/i18next/i18next-parser) | ||
], | ||
js: [ | ||
{ | ||
lexer: 'JavascriptLexer', | ||
acorn: { | ||
plugins: { | ||
jsx: true, | ||
objectRestSpread: true, | ||
es7: true | ||
} | ||
} | ||
} | ||
] | ||
// ... | ||
@@ -163,0 +175,0 @@ } |
import * as acorn from 'acorn-jsx' | ||
import injectAcornObjectRestSpread from "acorn-object-rest-spread/inject" | ||
import injectAcornEs7 from "acorn-es7" | ||
import * as walk from 'acorn/dist/walk' | ||
@@ -17,4 +19,15 @@ import BaseLexer from './base-lexer' | ||
let localAcorn = acorn | ||
if (this.acornOptions.plugins) { | ||
if (this.acornOptions.plugins.es7) { | ||
injectAcornEs7(localAcorn) | ||
} | ||
if (this.acornOptions.plugins.objectRestSpread) { | ||
injectAcornObjectRestSpread(localAcorn) | ||
} | ||
} | ||
walk.simple( | ||
acorn.parse(content, this.acornOptions), | ||
localAcorn.parse(content, this.acornOptions), | ||
{ | ||
@@ -21,0 +34,0 @@ CallExpression(node) { |
@@ -87,2 +87,21 @@ import { assert } from 'chai' | ||
}) | ||
it('supports the acorn-es7 plugin', (done) => { | ||
const Lexer = new JavascriptLexer({ acorn: { plugins: { es7: true } } }) | ||
const content = '@decorator() class Test { test() { t("foo") } }' | ||
assert.deepEqual(Lexer.extract(content), [ | ||
{ key: 'foo' } | ||
]) | ||
done() | ||
}) | ||
it('supports the acorn-object-rest-spread plugin', (done) => { | ||
const Lexer = new JavascriptLexer({ acorn: { plugins: { objectRestSpread: true } } }) | ||
const content = 'const data = { text: t("foo"), ...rest }; const { text, ...more } = data;' | ||
assert.deepEqual(Lexer.extract(content), [ | ||
{ key: 'foo' } | ||
]) | ||
done() | ||
}) | ||
}) |
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
454896
3695
227
17
+ Addedacorn-es7@^0.1.0
+ Addedacorn@2.7.0(transitive)
+ Addedacorn-es7@0.1.0(transitive)
+ Addedacorn-object-rest-spread@1.1.0(transitive)