Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
};
render(
<div>
<h1>Hello</h1>
<input placeholder="Hello" type="number">
</div>
)
`;
const result = babel.transform(code, {
plugins: [
["../plugins/TwoWayDataBinding.js", {
"attrName": "f-model"
}],
["../plugins/IfDirection.js", {
"attrName": "f-if"
}],
"transform-jsx"
]
});
// console.log(result);
var codeBlocks = tokens.reduce(function (blocks, token) {
if (token.type === 'code') {
blocks.push(new Buffer(token.text));
blocks.push(new Buffer(SEPARATOR));
}
return blocks;
}, []);
codeBlocks.pop(); // remove trailing EOL adding from the while loop
// Concatentate the code blocks.
buf = Buffer.concat(codeBlocks);
// Return the concatenated code blocks as a `Buffer`.
return new Buffer(babel.transform(buf.toString(), opts).code);
}
function buildFile(filename, destination, babelOptions = {}) {
const options = Object.assign({}, babelOptions);
const content = fs.readFileSync(filename, {encoding: 'utf8'});
const ext = path.extname(filename);
const outputPath = path.join(destination, path.basename(filename));
// Ignore non-JS files and test scripts
if (!filename.includes('.test.')) {
if (ext === '.js') {
options.filename = filename;
const result = transform(content, options);
return outputFileSync(outputPath, result.code, {encoding: 'utf8'});
}
// process with postcss if it's a css file
if (ext === '.css') {
return execSync(`postcss ${filename} -o ${outputPath}`);
}
// Copy if it's any other type of file
return outputFileSync(outputPath, content);
}
return false;
}
var sourceRoot = pathToUrl(path.dirname(load.path) + '/');
var options = {
babelrc: false,
compact: false,
sourceType: 'script',
filename: pathToUrl(load.path),
filenameRelative: path.basename(load.path),
inputSourceMap: load.metadata.sourceMap,
moduleId: opts.moduleId,
sourceFileName: path.basename(load.path),
sourceMaps: !!opts.sourceMaps,
sourceRoot: sourceRoot,
plugins: [plugin]
};
var output = babel.transform(load.source, options);
var sourceMap = output.map;
if (sourceMap && !sourceMap.sourceRoot) // if input source map doesn't have sourceRoot - add it
sourceMap.sourceRoot = sourceRoot;
return Promise.resolve({
source: output.code,
sourceMap: sourceMap
});
};
make_module(state, path, (module) => {
const code = read_file(path);
const dir = $path.dirname(path);
const output = $babel.transform(code, {
"filename": path, // TODO is this correct ?
"sourceMaps": true,
"code": true,
"babelrc": false,
"ast": false,
// sourceMapTarget
// sourceFileName
// sourceRoot
// moduleIds
// moduleId
"presets": [
"es2015-native-modules"
],
"plugins": [
[$module, {
"file": path,
export function combineElements(elements, options) {
if (options.wrapper == "no-wrap") {
if (elements.length != 1)
throw new Error(errors.NO_WRAP_ERROR);
}
if (elements.length == 1) return elements[0];
let wrapper = options.wrapper || "<span>";
if (wrapper == "array-supported") {
return t.arrayExpression(elements.reduce(toJSExpression, []));
}
try {
let {ast} = babel.transform(wrapper, { plugins: ["syntax-jsx"] });
let [expressionStatement] = ast.program.body;
if (!t.isExpressionStatement(expressionStatement))
throw null;
let wrapperASTSource = expressionStatement.expression;
if (!t.isJSXElement(wrapperASTSource))
throw null;
let openingElementSource = wrapperASTSource.openingElement;
let { name: tagIdentifier } = openingElementSource;
let openingElement =
t.jSXOpeningElement(tagIdentifier, openingElementSource.attributes);
let closingElement = t.jSXClosingElement(tagIdentifier);</span>
function transformSource(source, stripTypes) {
const { code } = transform(source, {
presets: [["es2015", { modules: false }]],
plugins: [stripTypes ? "transform-flow-strip-types" : "syntax-flow"]
});
return code;
}
function transform(filename, code, opts) {
opts = defaults(opts || {}, index.opts);
opts.filename = filename;
var result = babel.transform(code, opts);
result.filename = filename;
result.actual = code;
return result;
}
function transform(code, opts) {
return babel.transform(code, Object.assign({
sourceMaps: true,
sourceRoot: '/',
ast: false,
}, opts))
}
const compile = code =>
transform(code, {
presets: [
require('babel-preset-env'),
require('babel-preset-stage-0'),
require('babel-preset-react')
]
}).code