
Product
Introducing Webhook Events for Pull Request Scans
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.
@salesforce/acorn-visualforce
Advanced tools
acorn extension for Salesforce js dialect with merge fields
This is plugin for Acorn - a tiny, fast JavaScript parser, written completely in JavaScript.
It was created as an experimental parser for VisualForce inline JS.
You can use module directly in order to get Acorn instance with plugin installed:
const acorn = require('@salesforce/acorn-visualforce');
Or you can use inject.js
for injecting plugin into your own version of Acorn like following:
const acorn = require('@salesforce/acorn-visualforce/dist/inject')(require('./custom-acorn'));
Then, use plugins
option whenever you need to support VisualForce merge fields while parsing:
const code = 'var foo = {! JSENCODE(someApexVariable) };'
const ast = acorn.parse(code, {
plugins: {
jsx: true, // make sure that jsx appears BEFORE vfel to work correctly
vfel: true,
}
});
Produces:
{
"type": "Program",
"start": 0,
"end": 42,
"body": [{
"type": "VariableDeclaration",
"start": 0,
"end": 42,
"declarations": [{
"type": "VariableDeclarator",
"start": 4,
"end": 41,
"id": {
"type": "Identifier",
"start": 4,
"end": 7,
"name": "foo"
},
"init": {
"type": "VFELExpression",
"start": 10,
"end": 41,
"value": {
"type": "CallExpression",
"start": 12,
"end": 39,
"callee": {
"type": "Identifier",
"start": 12,
"end": 21,
"name": "JSENCODE"
},
"arguments": [{
"type": "Identifier",
"start": 22,
"end": 38,
"name": "someApexVariable"
}]
}
}
}],
"kind": "var"
}],
"sourceType": "script"
}
The injector function also supports an optional second parameter that allows to force-inject the plugin, so that there is no need to specify the plugins options to parse or tokenize functions. This is useful for monkey-patching other parser wrappers such as espree
that force their own plugin options.
const acorn = require('@salesforce/acorn-visualforce/dist/inject')(require('./custom-acorn'), true);
const code = 'var foo = {! JSENCODE(someApexVariable) };'
const ast = acorn.parse(code);
This plugin is issued under the BSD-3-Clause license.
FAQs
acorn extension for Salesforce js dialect with merge fields
We found that @salesforce/acorn-visualforce demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.
Research
The Socket Threat Research Team uncovered malicious NuGet packages typosquatting the popular Nethereum project to steal wallet keys.
Product
A single platform for static analysis, secrets detection, container scanning, and CVE checks—built on trusted open source tools, ready to run out of the box.