From 1abdd11ad63213d6b881606f8da0fb01b034308c Mon Sep 17 00:00:00 2001 From: Jon Jensen Date: Mon, 6 Mar 2017 22:32:04 -0700 Subject: [PATCH] bump dependencies fixes #21, #23 work with the latest i18nliner, which uses babel and gives us all the latest es goodness --- __tests__/preprocess.test.js | 8 +++++++- main.js | 3 +-- package.json | 5 +++-- preprocess.js | 19 +++++++++---------- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/__tests__/preprocess.test.js b/__tests__/preprocess.test.js index 30a6540..2efeab9 100644 --- a/__tests__/preprocess.test.js +++ b/__tests__/preprocess.test.js @@ -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() { diff --git a/main.js b/main.js index 904b861..bf0be92 100644 --- a/main.js +++ b/main.js @@ -1,5 +1,4 @@ var preprocess = require("./preprocess"); -var recast = require("recast"); module.exports = function(i18nliner) { var JsProcessor = i18nliner.processors.JsProcessor; @@ -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; } diff --git a/package.json b/package.json index e809ee6..1e42412 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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" } } diff --git a/preprocess.js b/preprocess.js index 2fc5b52..a10a62c 100644 --- a/preprocess.js +++ b/preprocess.js @@ -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") @@ -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); }; @@ -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)) { @@ -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( @@ -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 @@ -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); @@ -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) { @@ -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; };