Created
March 27, 2016 19:19
-
-
Save alex-kinokon/a595a7e72180db0bda25 to your computer and use it in GitHub Desktop.
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
import { reserved-words } from '../util/identifier' | |
import { get-options } from '../options' | |
import Tokenizer from '../tokenizer' | |
export const plugins = {} | |
export default class Parser extends Tokenizer | |
(options, @input) -> | |
options = get-options options | |
super options, @input | |
@options = options | |
@in-module = @options.source-type is 'module' | |
@is-reserved-word = reserved-words[6] | |
@input = input | |
@plugins = @load-plugins @options.plugins | |
@filename = options.source-filename | |
# If enabled, skip leading hashbang line. | |
if @state.pos is 0 and @input.starts-with '#!' | |
@skip-line-comment 2 | |
has-plugin: (name) -> | |
Boolean (@plugins['*'] or @plugins[name]) | |
extend: (name, f) -> | |
@[name] = f @[name] | |
# load-plugins :: (string[]) -> Object | |
load-plugins: (plugins) -> | |
plugin-map = {} | |
if plugins.includes 'flow' | |
# ensure flow plugin loads last | |
plugins .= filter (isnt 'flow') | |
plugins.push 'flow' | |
for name in plugins when not plugin-map[name] | |
plugin-map[name] = true | |
plugin = plugins[name] | |
plugin this if plugin | |
plugin-map | |
# parse :: -> { type: 'File', program: { type: 'Program', body: Object[] }} | |
parse: -> | |
file = @start-node! | |
program = @start-node! | |
@next-token! | |
@parse-top-level file, program |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment