Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// @flow
import semver from 'semver';
import path from 'path';
import {Transformer} from '@parcel/plugin';
import {relativeUrl} from '@parcel/utils';
import SourceMap from '@parcel/source-map';
import generate from '@babel/generator';
import {parse} from '@babel/parser';
import template from '@babel/template';
import * as t from '@babel/types';
const WRAPPER = path.join(__dirname, 'helpers', 'helpers.js');
const wrapper = template(`
var helpers = require(%%helper%%);
var prevRefreshReg = window.$RefreshReg$;
var prevRefreshSig = window.$RefreshSig$;
helpers.prelude(module);
try {
%%module%%
helpers.postlude(module);
} finally {
window.$RefreshReg$ = prevRefreshReg;
window.$RefreshSig$ = prevRefreshSig;
}
`);
function shouldExclude(asset, options) {
return (
it('should throw if has invalid argument', () => {
const node = template('gettext(fn())')().expression;
const fn = () => gettext.validate(node, enConfig);
expect(fn).to.throw('You can not use CallExpression \'fn()\' as an argument to gettext');
});
it('should match gettext with zero arguments', () => {
const node = template('gettext()')().expression;
const result = gettext.match(node, enConfig);
expect(result).to.be.false;
});
});
it('should extract msgid with expressions', () => {
const node = template('nt(n)`${n} banana ${ b }`')().expression;
const expected = '${ n } banana ${ b }';
expect(template2Msgid(node, testContext)).to.eql(expected);
});
it('should throw if has invalid expressions', () => {
const node = template('t`banana ${ n + 1}`')().expression;
const fn = () => gettext.validate(node, enConfig);
expect(fn).to.throw('You can not use BinaryExpression \'${n + 1}\' in localized strings');
});
it('should extract msgid with expressions', () => {
const node = template('`test ${ a } ${ b }`')().expression;
const [strs, exprs] = getStrsExprs(node);
expect(getMsgidNumbered(strs, exprs)).to.be.eql('test ${ 0 } ${ 1 }');
});
it('should extract msgid without expressions', () => {
import { addNamed } from '@babel/helper-module-imports';
import template from '@babel/template';
import { NodePath } from '@babel/traverse';
import { ExpressionStatement, TryStatement } from '@babel/types';
import { AssertionPostProcessor } from '@spockjs/config';
import autoImportDisabled from './auto-import-disabled-warning';
const createTryStatement = template(`
try {
ASSERTION
} catch(e) {
if (e instanceof ASSERTION_ERROR) {
throw new Error(e.message);
}
throw e;
}
`);
const processor: AssertionPostProcessor = (t, { autoImport }) => (
originalPath,
patterns,
) => {
const assertionErrorImportedName = 'AssertionError';
const assertionErrorLocal = autoImport
export default function ({types: t}) {
const defaultIdentifier = t.identifier('default');
const rewireIdentifier = t.identifier('rewire');
const restoreIdentifier = t.identifier('restore');
const stubIdentifier = t.identifier('$stub');
const VISITED = Symbol('visited');
const buildStub = template(`
export function REWIRE(STUB) {
LOCAL = STUB;
}
`, {sourceType: 'module'});
const buildRestore = template(`
export function RESTORE() {
BODY
}
`, {sourceType: 'module'});
function buildNamedExport(local, exported) {
return markVisited(t.exportNamedDeclaration(null, [
t.exportSpecifier(t.identifier(local.name), t.identifier(exported.name))
]));
}
import { PluginObj } from '@babel/core'
import template from '@babel/template'
import { NodePath } from '@babel/traverse'
import * as BabelTypes from '@babel/types'
const requireRHL = template(
'require(\'react-hot-loader/root\').hot'
)()
export default function ({ types: t }: { types: typeof BabelTypes }): PluginObj {
return {
pre: (file) => {
let importController
let controller
file.path.traverse({
ImportDeclaration (importPath) {
if (importPath.node.source.value === '@symph/joy/controller') {
importController = importPath
controller = importPath.get('specifiers').find(item => item.get('type').node === 'ImportDefaultSpecifier' || item.get('imported.name').node === 'controller')
}
}
})
function ngettextTemplate(ngettext, pluralForm) {
return tpl(`function NGETTEXT(n, args) { ${pluralFnBody(pluralForm)} }`)({ NGETTEXT: ngettext });
}