Skip to content

Commit

Permalink
bump dependencies
Browse files Browse the repository at this point in the history
fixes #21, #23

work with the latest i18nliner, which uses babel and gives us all the
latest es goodness
  • Loading branch information
jenseng committed Mar 7, 2017
1 parent 375f997 commit 1abdd11
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
8 changes: 7 additions & 1 deletion __tests__/preprocess.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
jest.autoMockOff();
var preprocess = require('../preprocess');
var JsProcessor = require('i18nliner/dist/lib/processors/js_processor').default;

var subject = function() {
return preprocess.apply(null, arguments).replace(/\s+/g, ' ');
var args = [].slice.apply(arguments);
args[0] = JsProcessor.prototype.parse(args[0]);
return preprocess.apply(null, args)
.replace(/\s+/g, ' ')
.replace(/;$/, '');
};

describe('preprocess', function() {
Expand Down
3 changes: 1 addition & 2 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var preprocess = require("./preprocess");
var recast = require("recast");

module.exports = function(i18nliner) {
var JsProcessor = i18nliner.processors.JsProcessor;
Expand All @@ -14,7 +13,7 @@ module.exports = function(i18nliner) {
fileData.skip = fileData.skip && !hasTranslatableText(source);

if (!fileData.skip) {
var ast = fileData.ast || recast.parse(source, config.recastOptions);
var ast = fileData.ast || this.parse(source);
preprocess.ast(ast, config);
fileData.ast = ast;
}
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
"babel-preset-react": "^6.5.0",
"eslint": "^2.12.0",
"eslint-plugin-react": "^5.1.1",
"i18nliner": "~0.2.1",
"jest-cli": "^12.1.1",
"react": "^15.0.0",
"react-addons-test-utils": "^15.1.0",
"react-dom": "^15.1.0"
},
"peerDependencies": {
"i18nliner": "~0.2.1",
"react": "0.13.x || 0.14.x || ^15.0.0"
},
"jest": {
Expand All @@ -33,9 +35,8 @@
]
},
"dependencies": {
"i18nliner": "^0.1.5",
"invariant": "2.2.1",
"recast": "^0.10.12",
"recast": "^0.11.12",
"through2": "^0.6.3"
}
}
19 changes: 9 additions & 10 deletions preprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var translatableAttributes = {
var isTranslatableAttribute = function(node, attribute) {
var name = attribute.name.name;
if (!translatableAttributes[name]) return false;
if (attribute.value.type !== "Literal") return false;
if (attribute.value.type !== "StringLiteral") return false;

var rules = translatableAttributes[name];
if (typeof rules === "function")
Expand All @@ -45,7 +45,7 @@ var findIndex = function(fn, ary) {
};

var hasLiteralContent = function(node) {
if (node.type === "Literal") return true;
if (node.type === "JSXText") return true;
if (node.type !== "JSXElement") return false;
return node.children && node.children.some(hasLiteralContent);
};
Expand Down Expand Up @@ -89,7 +89,7 @@ var findAttribute = function(attribute, node, shouldSpliceFn) {
if (index < 0) return;

var value = attributes[index].value;
if (attributes[index].value.type !== "Literal") return;
if (attributes[index].value.type !== "StringLiteral") return;

value = value.value;
if (shouldSpliceFn && shouldSpliceFn(value)) {
Expand Down Expand Up @@ -155,7 +155,7 @@ function transformationsFor(config) {
if (Object.keys(wrappers).length) {
var wrappersNode = b.objectExpression([]);
for (key in wrappers) {
wrappersNode.properties.push(b.property("init", b.literal(key), wrappers[key]));
wrappersNode.properties.push(b.property("init", b.stringLiteral(key), wrappers[key]));
}
properties.push(
b.jsxAttribute(
Expand Down Expand Up @@ -186,14 +186,14 @@ function transformationsFor(config) {
b.jsxIdentifier(interpolatorName)
),
children.map(function(child) {
return typeof child === "string" ? b.literal(child) : child;
return typeof child === "string" ? b.stringLiteral(child) : child;
})
);
};

var translateCallFor = function(loc, string) {
var args = [
b.literal(string)
b.stringLiteral(string)
];

// create dummy placeholders; we want ComponentInterpolator to do the
Expand All @@ -205,7 +205,7 @@ function transformationsFor(config) {
while (tokens.length) {
var token = tokens.shift();
if (token.match(PLACEHOLDER_PATTERN)) {
optionsNode.properties.push(b.property("init", b.literal(token.slice(2, -1)), b.literal(token)));
optionsNode.properties.push(b.property("init", b.stringLiteral(token.slice(2, -1)), b.stringLiteral(token)));
}
}
args.push(optionsNode);
Expand Down Expand Up @@ -287,7 +287,7 @@ function transformationsFor(config) {
node.children.forEach(function(child) {
var part;
var translatable = isTranslatable(child, true);
if (child.type === "Literal") {
if (child.type === "JSXText") {
part = child.value;
lastPartType = "literal";
} else if (hasLiteralContent(child) && translatable) {
Expand Down Expand Up @@ -364,9 +364,8 @@ function transformationsFor(config) {
};
}

var preprocess = function(source, config) {
var preprocess = function(ast, config) {
config = config || {};
var ast = recast.parse(source, config.recastOptions);
preprocessAst(ast, config);
return recast.print(ast).code;
};
Expand Down

0 comments on commit 1abdd11

Please sign in to comment.