### Install shift-parser (sh) Source: https://github.com/shapesecurity/shift-parser-js/blob/es2019/README.md Demonstrates the command to install the shift-parser package using npm. This is the first step before using the parser in your project. ```sh npm install shift-parser ``` -------------------------------- ### Parse Script with shift-parser (Node.js) Source: https://github.com/shapesecurity/shift-parser-js/blob/es2019/README.md Illustrates how to use `parseScript` in a Node.js environment using the `require` syntax. This is a common pattern for server-side JavaScript. ```js var parseScript = require("shift-parser").parseScript; var scriptAST = parseScript("/* ECMAScript Script text */"); ``` -------------------------------- ### Parse with Location Info using shift-parser (js) Source: https://github.com/shapesecurity/shift-parser-js/blob/es2019/README.md Explains how to obtain location information (line, column, offset) and comments associated with parsed AST nodes. Requires an environment supporting `WeakMap`. ```js let {parseScriptWithLocation, parseModuleWithLocation} = require("shift-parser"); let {tree, locations, comments} = parseScriptWithLocation("2 + 3 /* = 5 */"); let threeNode = tree.statements[0].expression.right; locations.get(threeNode); // { start: { line: 1, column: 4, offset: 4 }, end: { line: 1, column: 5, offset: 5 } } comments; // [ { text: ' = 5 ', type: 'MultiLine', start: { line: 1, column: 6, offset: 6 }, end: { line: 1, column: 15, offset: 15 } } ] ``` -------------------------------- ### Parse ECMAScript with shift-parser (es6) Source: https://github.com/shapesecurity/shift-parser-js/blob/es2019/README.md Demonstrates the basic usage of the `parse` function from `shift-parser` to convert ECMAScript code into an Abstract Syntax Tree (AST). Requires the `shift-parser` package. ```es6 import parse from "shift-parser"; let ast = parse("/* ECMAScript program text */"); ``` -------------------------------- ### Parse Script/Module with shift-parser (es6) Source: https://github.com/shapesecurity/shift-parser-js/blob/es2019/README.md Shows how to import and use `parseScript` and `parseModule` for parsing specific ECMAScript constructs. Useful for differentiating between scripts and modules. ```es6 import {parseScript, parseModule} from "shift-parser"; let scriptAST = parseScript("/* ECMAScript Script text */"); let moduleAST = parseModule("/* ECMAScript Module text */"); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.