Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function parse(string, opts) {
return prettier.__debug.parse(string, opts, /* massage */ true).ast;
}
const { spawn, spawnSync } = require("child_process");
const path = require("path");
const prettier = require("prettier");
const readline = require("readline");
// Set RUBY_VERSION so certain tests only run for certain versions
process.env.RUBY_VERSION = spawnSync("ruby", ["-e", "puts RUBY_VERSION"])
.stdout.toString()
.trim();
// eslint-disable-next-line no-underscore-dangle
const { formatAST } = prettier.__debug;
const parser = spawn("ruby", ["./test/js/parser.rb"]);
afterAll(() => parser.kill());
const rl = readline.createInterface({
input: parser.stdout,
output: parser.stdin
});
const checkFormat = (before, after, config) =>
new Promise(resolve => {
const opts = Object.assign({ parser: "ruby", plugins: ["."] }, config);
rl.question(`${before}\n---\n`, response => {
const { formatted } = formatAST(JSON.parse(response), opts);
function parse(string, opts) {
// eslint-disable-next-line no-underscore-dangle
return prettier.__debug.parse(
string,
{
apexStandaloneParser: "built-in",
apexStandalonePort: 2117,
apexStandaloneHost: "localhost",
...opts,
},
/* massage */ true,
).ast;
}
!t.isStringLiteral(attr.value)
) {
return;
}
if (!seenValues[attr.value.value]) {
try {
if (attr.value.value.includes(';')) {
throw new Error('CSS values cannot contain semicolons');
}
// the minimal amount of CSS that the CSS parser can parse
const wrapped = `__jsxstyle__:${attr.value.value};`;
const cssAst = postcssParser.parsers.css.parse(wrapped, null, {});
const value = prettier.__debug.formatAST(cssAst.nodes[0].value, {
filepath: 'example.css',
printWidth: 1000,
});
if (typeof value.formatted !== 'string') {
throw new Error('formatted value is not a string!');
}
seenValues[attr.value.value] = value.formatted;
} catch (e) {
console.error(e);
return;
}
}
attr.value = t.stringLiteral(seenValues[attr.value.value]);
function parse(string, opts) {
return stripExtraNonComparableKeys(prettier.__debug.parse(string, opts));
}
function parse(string, opts) {
return stripLocation(prettier.__debug.parse(string, opts));
}