let babelTransfrom = (plain) => { try { let matchCommonJS = (opt) => opt === 'transform-es2015-modules-commonjs'; let strict = false; if(global.Mancy.session.mode === 'Strict') { strict = true; if(_.findIndex(ReplConstants.BABEL_OPTIONS.plugins, matchCommonJS) === -1) { ReplConstants.BABEL_OPTIONS.plugins.push('transform-es2015-modules-commonjs'); } } else { _.remove(ReplConstants.BABEL_OPTIONS.plugins, matchCommonJS); } let code = babel .transform(plain, ReplConstants.BABEL_OPTIONS) .code; // transform imports added by babel scripts into require if(!strict && code.indexOf('import') !== -1) { code = code.replace(importMatcher, importToRequire); } return strict ? code.substring(USE_STRICT_LENGTH - 1) : code; } catch(e) { return e; } }
it('transforms "react-native-config"" to "react-native-config-node"', function () { const code = 'import abc from "react-native-config";' const expected = 'import abc from "react-native-config-node";' const actual = babel.transform(code, { plugins: [pluginPath] }).code assert(actual === expected) })
function parseFixture(fixtureFile, opts) { opts = opts || {}; const presets = opts.presets || []; const plugins = opts.plugins || [[detective, opts]]; const babelOpts = { presets: presets, plugins: plugins }; return babel.transformFileSync(getFixturePath(fixtureFile), babelOpts); }
const extractFromFile = async (fileName) => { try { const code = await readFile(fileName); // Use babel plugin to extract instances where react-intl is used const { metadata: result } = await transform(code, { presets, plugins }); // object-shorthand for (const message of result['react-intl'].messages) { for (const locale of locales) { const oldLocaleMapping = oldLocaleMappings[locale][message.id]; // Merge old translations into the babel extracted instances where react-intl is used const newMsg = ( locale === DEFAULT_LOCALE) ? message.defaultMessage : ''; localeMappings[locale][message.id] = (oldLocaleMapping) ? oldLocaleMapping : newMsg; } } } catch (error) { process.stderr.write(`Error transforming file: ${fileName}\n${error}`); } }
const extractFromFile = async (fileName) => { try { const code = await readFile(fileName); // Use babel plugin to extract instances where react-intl is used const { metadata: result } = await transform(code, { presets, plugins }); // object-shorthand for (const message of result['react-intl'].messages) { for (const locale of locales) { const oldLocaleMapping = oldLocaleMappings[locale][message.id]; // Merge old translations into the babel extracted instances where react-intl is used const newMsg = ( locale === DEFAULT_LOCALE) ? message.defaultMessage : ''; localeMappings[locale][message.id] = (oldLocaleMapping) ? oldLocaleMapping : newMsg; } } } catch (error) { process.stderr.write(`Error transforming file: ${fileName}\n${error}`); } }
const extractFromFile = async (fileName) => { try { const code = await readFile(fileName); // Use babel plugin to extract instances where react-intl is used const { metadata: result } = await transform(code, { presets, plugins }); // object-shorthand for (const message of result['react-intl'].messages) { for (const locale of locales) { const oldLocaleMapping = oldLocaleMappings[locale][message.id]; // Merge old translations into the babel extracted instances where react-intl is used const newMsg = ( locale === DEFAULT_LOCALE) ? message.defaultMessage : ''; localeMappings[locale][message.id] = (oldLocaleMapping) ? oldLocaleMapping : newMsg; } } } catch (error) { process.stderr.write(`Error transforming file: ${fileName}\n${error}`); } }
const extractFromFile = async (fileName) => { try { const code = await readFile(fileName); // Use babel plugin to extract instances where react-intl is used const { metadata: result } = await transform(code, { presets, plugins }); // object-shorthand for (const message of result['react-intl'].messages) { for (const locale of locales) { const oldLocaleMapping = oldLocaleMappings[locale][message.id]; // Merge old translations into the babel extracted instances where react-intl is used const newMsg = ( locale === DEFAULT_LOCALE) ? message.defaultMessage : ''; localeMappings[locale][message.id] = (oldLocaleMapping) ? oldLocaleMapping : newMsg; } } } catch (error) { process.stderr.write(`Error transforming file: ${fileName}\n${error}`); } }