Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'pn' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
describe(`Compiling ${l.base}.foma`, function() {
this.timeout(100000); /* compilation can take a while */
const fomaFile = `${l.base}${l.examples ? '-examples' : ''}.foma`;
// This has to be sync, since we're going to create test cases
// based on the result of this, and mocha doesn't support async
// test case generation.
// XXX skip this if `foma` isn't on the path.
let result = childProcess.execFileSync('foma', ['-f', fomaFile], {
cwd: fstDir,
encoding: 'utf8',
});
// Count the number of tests expected
let expectedTests = 0;
result = result.replace(
/^EXPECT\s+(\d+)\s*$/mg,
(m, num) => {
expectedTests += Number.parseInt(num, 10);
return '';
});
// EXPECT: is a shorthand for one-line tests
result = result.replace(
/^EXPECT(?:\[(.*)\])?: (.*)$/mg,
(m, name, out) => `\n${out}\n`
console.assert(yield fs.exists(oldFile));
if (!(yield fs.exists(newFile))) { continue; /* Skip this */ }
/* check for the watermark string; only overwrite if it is present */
/* this ensures we don't overwrite actually-ported files */
if (!WATERMARK_RE.test(yield fs.readFile(newFile, 'utf8'))) { continue; }
/* run our translation tool! */
var isPeg = /\.pegjs$/.test(oldFile);
try {
var args = (isPeg ? [ '--braced' ] : [])
.concat([
'--namespace', 'Parsoid',
'--watermark', WATERMARK,
oldFile, newFile,
]);
yield childProcess.execFile(
path.join(BASEDIR, 'node_modules', '.bin', 'js2php'), args, {
cwd: BASEDIR,
env: process.env,
}).promise;
} catch (e1) {
console.log(`SKIPPING ${oldFile}`);
continue;
}
if (isPeg) { continue; }
// Now run phpcbf, but it's allowed to return non-zero
try {
yield childProcess.execFile(
path.join(BASEDIR, 'vendor', 'bin', 'phpcbf'), [
newFile,
]).promise;
} catch (e2) { /* of course there were code style issues */ }
stdio: 'inherit',
}).on('close', function(code) {
if (code === 0) {
resolve(code);
} else {
reject(code);
}
}).on('error', reject);
});
};
var pPARSERTESTS = path.join(__dirname, '..', 'tests', 'parser', targetName);
var mwPARSERTESTS = path.join(mwpath, file.path);
// Fetch current Parsoid git hash.
var result = yield childProcess.execFile(
'git', ['log', '--max-count=1', '--pretty=format:%H'], {
cwd: __dirname,
env: process.env,
}).promise;
var phash = strip(result.stdout);
// A bit of user-friendly logging.
console.log('Parsoid git HEAD is', phash);
console.log('>>> cd', mwpath);
// Create a new mediawiki/core branch, based on the previous sync point.
yield mwexec('git fetch origin'.split(' '));
yield mwexec(['git', 'checkout', '-b', branch, oldhash]);
// Copy our locally-modified parser tests over to mediawiki/core.
// cp __dirname/tests/parser/parserTests.txt $mwpath/tests/parser
Promise.async(function *() {
const files = (yield childProcess.execFile(
'git', ['ls-files'], {
cwd: path.join(BASEDIR, 'lib'),
env: process.env,
}).promise).stdout.split(/\n/g).filter(s => !!s);
for (let oldFile of files) {
const newFile = path.join(BASEDIR, 'src', remapName(oldFile));
oldFile = path.join(BASEDIR, 'lib', oldFile);
console.assert(yield fs.exists(oldFile));
if (!(yield fs.exists(newFile))) { continue; /* Skip this */ }
/* check for the watermark string; only overwrite if it is present */
/* this ensures we don't overwrite actually-ported files */
if (!WATERMARK_RE.test(yield fs.readFile(newFile, 'utf8'))) { continue; }
/* run our translation tool! */
var isPeg = /\.pegjs$/.test(oldFile);
try {
Promise.async(function *() {
const files = (yield childProcess.execFile(
'git', ['ls-files'], {
cwd: path.join(BASEDIR, 'lib'),
env: process.env,
}).promise).stdout.split(/\n/g).filter(s => !!s);
for (let oldFile of files) {
const newFile = path.join(BASEDIR, 'src', remapName(oldFile));
oldFile = path.join(BASEDIR, 'lib', oldFile);
console.assert(yield fs.exists(oldFile));
if (!(yield fs.exists(newFile))) { continue; /* Skip this */ }
/* check for the watermark string; only overwrite if it is present */
/* this ensures we don't overwrite actually-ported files */
if (!WATERMARK_RE.test(yield fs.readFile(newFile, 'utf8'))) { continue; }
/* run our translation tool! */
var isPeg = /\.pegjs$/.test(oldFile);
try {
var args = (isPeg ? [ '--braced' ] : [])
.concat([
'--namespace', 'Parsoid',
'--watermark', WATERMARK,
oldFile, newFile,
]);
yield childProcess.execFile(
path.join(BASEDIR, 'node_modules', '.bin', 'js2php'), args, {
cwd: BASEDIR,
Promise.async(function *() {
const files = (yield childProcess.execFile(
'git', ['ls-files'], {
cwd: path.join(BASEDIR, 'lib'),
env: process.env,
}).promise).stdout.split(/\n/g).filter(s => !!s);
for (let oldFile of files) {
const newFile = path.join(BASEDIR, 'src', remapName(oldFile));
oldFile = path.join(BASEDIR, 'lib', oldFile);
console.assert(yield fs.exists(oldFile));
if (!(yield fs.exists(newFile))) { continue; /* Skip this */ }
/* check for the watermark string; only overwrite if it is present */
/* this ensures we don't overwrite actually-ported files */
if (!WATERMARK_RE.test(yield fs.readFile(newFile, 'utf8'))) { continue; }
/* run our translation tool! */
var isPeg = /\.pegjs$/.test(oldFile);
try {
var args = (isPeg ? [ '--braced' ] : [])
.concat([
'--namespace', 'Parsoid',
'--watermark', WATERMARK,
oldFile, newFile,
]);
yield childProcess.execFile(
path.join(BASEDIR, 'node_modules', '.bin', 'js2php'), args, {
.then(function() {
if (argv.inputfile) {
// read input from the file, then process
return fs.readFile(argv.inputfile, 'utf8');
}
// Send a message to stderr if there is no input for a while, since the
// convention that --pageName must be used with
result.on('data', function(data) { res += data; });
result.on('end', function() { resolve(res); });
}).on('error', function(err) {
console.error(err);
reject(err);
});
}))[0].sha;
// download latest file
yield fetch(targetName, gitCommit, true);
var fileHash = yield computeSHA1(targetName);
// now rewrite this file!
file.expectedSHA1 = fileHash;
file.latestCommit = gitCommit;
yield fs.writeFile(testFilesPath, JSON.stringify(testFiles, null, '\t'), 'utf8');
console.log('Updated', testFilesPath);
});
var fetch = Promise.async(function *(page, revid, opts) {
var prefix = opts.prefix || null;
var domain = opts.domain || null;
if (!prefix && !domain) {
domain = "en.wikipedia.org";
}
var parsoidOptions = {};
if (ScriptUtils.booleanOption(opts.config)) {
var p = (typeof (opts.config) === 'string') ?
path.resolve('.', opts.config) :
path.resolve(__dirname, '../config.yaml');
// Assuming Parsoid is the first service in the list
parsoidOptions = yaml.load(yield fs.readFile(p, 'utf8')).services[0].conf;
}
ScriptUtils.setTemplatingAndProcessingFlags(parsoidOptions, opts);
ScriptUtils.setDebuggingFlags(parsoidOptions, opts);
if (parsoidOptions.localsettings) {
parsoidOptions.localsettings = path.resolve(__dirname, parsoidOptions.localsettings);
}
var pc = new ParsoidConfig(null, parsoidOptions);
if (!prefix) {
// domain has been provided
prefix = pc.getPrefixFor(domain);
} else if (!domain) {
// prefix has been set
domain = pc.mwApiMap.get(prefix).domain;
} else if (!(prefix || domain)) {
domain = 'en.wikipedia.org';
}
var parsoidOptions = {
linting: argv.linting,
loadWMF: argv.loadWMF,
useWorker: argv.useWorker,
};
if (ScriptUtils.booleanOption(argv.config)) {
var p = (typeof (argv.config) === 'string') ?
path.resolve('.', argv.config) :
path.resolve(__dirname, '../config.yaml');
// Assuming Parsoid is the first service in the list
parsoidOptions = yaml.load(yield fs.readFile(p, 'utf8')).services[0].conf;
}
ScriptUtils.setTemplatingAndProcessingFlags(parsoidOptions, argv);
ScriptUtils.setDebuggingFlags(parsoidOptions, argv);
// Offline shortcut
if (argv.offline) {
parsoidOptions.fetchConfig = false;
parsoidOptions.fetchTemplates = false;
parsoidOptions.fetchImageInfo = false;
parsoidOptions.usePHPPreProcessor = false;
parsoidOptions.expandExtensions = false;
}
if (parsoidOptions.localsettings) {
parsoidOptions.localsettings = path.resolve(__dirname, parsoidOptions.localsettings);