esprima: Parse or Tokenize JavaScript code using Esprima
Description
Use the Esprima library to parse or tokenize JavaScript code. Note that the
first time this function is called, it will load the esprima library into the JavaScript context,
which may take a few seconds. Subsequent calls will be faster.
Usage
esprima_parse(input, options = NULL, type = "script")esprima_tokenize(input, options = list())
Value
For esprima_parse, a list representing the Abstract Syntax Tree (AST) of the parsed code.
For esprima_tokenize, a list of tokens extracted from the input code.
Arguments
- input
Either a path to a file or a character string containing the JavaScript code to be parsed or tokenized.
- options
A list of configuration options to pass to the Esprima parser or tokenizer.
- type
A character string specifying the type of code to parse: "script" (default) or "module".
Examples
Run this codejs_code <- 'const answer = 42;'
esprima_parse(js_code)
esprima_tokenize(js_code)
Run the code above in your browser using DataLab