-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Meriyah is a fast and modern implementation of ECMAScript parser
- Loading branch information
Showing
8 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// This module is suitable for passing as options.parser when calling | ||
// recast.parse to process JavaScript code with Meriyah: | ||
// | ||
// const ast = recast.parse(source, { | ||
// parser: require("recast/parsers/meriyah") | ||
// }); | ||
// | ||
import { getOption } from "../lib/util"; | ||
|
||
function convertComment(comment: any): any { | ||
let { type } = comment; | ||
type = type[0] === 'S' ? 'Line' : 'Block'; // SingleLine/MultiLine | ||
return { ...comment, type }; | ||
} | ||
|
||
export function parse(source: string, options?: any) { | ||
const comments: any[] = []; | ||
const tokens: any[] = []; | ||
const ast = require("meriyah").parse(source, { | ||
module: getOption(options, "sourceType", "module") === "module", | ||
specDeviation: getOption(options, "tolerant", true), | ||
jsx: getOption(options, "jsx", false), | ||
ranges: getOption(options, "range", false), | ||
loc: true, | ||
raw: true, | ||
next: true, | ||
globalReturn: true, | ||
onComment: comments, | ||
onToken: tokens, | ||
}); | ||
|
||
ast.comments = comments.map(convertComment); | ||
ast.tokens = tokens; | ||
|
||
return ast; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters