BVB Source Codes

reactide Show state.js Source code

Return Download reactide: download state.js Source code - Download reactide Source code - Type:.js
  1. import {reservedWords, keywords} from "./identifier"
  2. import {types as tt} from "./tokentype"
  3. import {lineBreak} from "./whitespace"
  4. import {getOptions} from "./options"
  5.  
  6. // Registered plugins
  7. export const plugins = {}
  8.  
  9. function keywordRegexp(words) {
  10.   return new RegExp("^(" + words.replace(/ /g, "|") + ")$")
  11. }
  12.  
  13. export class Parser {
  14.   constructor(options, input, startPos) {
  15.     this.options = options = getOptions(options)
  16.     this.sourceFile = options.sourceFile
  17.     this.keywords = keywordRegexp(keywords[options.ecmaVersion >= 6 ? 6 : 5])
  18.     let reserved = options.allowReserved ? "" :
  19.         reservedWords[options.ecmaVersion] + (options.sourceType == "module" ? " await" : "")
  20.     this.reservedWords = keywordRegexp(reserved)
  21.     let reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict
  22.     this.reservedWordsStrict = keywordRegexp(reservedStrict)
  23.     this.reservedWordsStrictBind = keywordRegexp(reservedStrict + " " + reservedWords.strictBind)
  24.     this.input = String(input)
  25.  
  26.     // Used to signal to callers of `readWord1` whether the word
  27.     // contained any escape sequences. This is needed because words with
  28.     // escape sequences must not be interpreted as keywords.
  29.     this.containsEsc = false
  30.  
  31.     // Load plugins
  32.     this.loadPlugins(options.plugins)
  33.  
  34.     // Set up token state
  35.  
  36.     // The current position of the tokenizer in the input.
  37.     if (startPos) {
  38.       this.pos = startPos
  39.       this.lineStart = Math.max(0, this.input.lastIndexOf("\n", startPos))
  40.       this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length
  41.     } else {
  42.       this.pos = this.lineStart = 0
  43.       this.curLine = 1
  44.     }
  45.  
  46.     // Properties of the current token:
  47.     // Its type
  48.     this.type = tt.eof
  49.     // For tokens that include more information than their type, the value
  50.     this.value = null
  51.     // Its start and end offset
  52.     this.start = this.end = this.pos
  53.     // And, if locations are used, the {line, column} object
  54.     // corresponding to those offsets
  55.     this.startLoc = this.endLoc = this.curPosition()
  56.  
  57.     // Position information for the previous token
  58.     this.lastTokEndLoc = this.lastTokStartLoc = null
  59.     this.lastTokStart = this.lastTokEnd = this.pos
  60.  
  61.     // The context stack is used to superficially track syntactic
  62.     // context to predict whether a regular expression is allowed in a
  63.     // given position.
  64.     this.context = this.initialContext()
  65.     this.exprAllowed = true
  66.  
  67.     // Figure out if it's a module code.
  68.     this.strict = this.inModule = options.sourceType === "module"
  69.  
  70.     // Used to signify the start of a potential arrow function
  71.     this.potentialArrowAt = -1
  72.  
  73.     // Flags to track whether we are in a function, a generator.
  74.     this.inFunction = this.inGenerator = false
  75.     // Labels in scope.
  76.     this.labels = []
  77.  
  78.     // If enabled, skip leading hashbang line.
  79.     if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === '#!')
  80.       this.skipLineComment(2)
  81.   }
  82.  
  83.   // DEPRECATED Kept for backwards compatibility until 3.0 in case a plugin uses them
  84.   isKeyword(word) { return this.keywords.test(word) }
  85.   isReservedWord(word) { return this.reservedWords.test(word) }
  86.  
  87.   extend(name, f) {
  88.     this[name] = f(this[name])
  89.   }
  90.  
  91.   loadPlugins(pluginConfigs) {
  92.     for (let name in pluginConfigs) {
  93.       let plugin = plugins[name]
  94.       if (!plugin) throw new Error("Plugin '" + name + "' not found")
  95.       plugin(this, pluginConfigs[name])
  96.     }
  97.   }
  98.  
  99.   parse() {
  100.     let node = this.options.program || this.startNode()
  101.     this.nextToken()
  102.     return this.parseTopLevel(node)
  103.   }
  104. }
  105.  
downloadstate.js Source code - Download reactide Source code
Related Source Codes/Software:
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
postal - 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top