Add support for import typeof, fixes #1975

This commit is contained in:
cpojer 2015-07-10 23:35:13 -07:00
parent 04a29f8344
commit f757ca01a1
3 changed files with 12 additions and 17 deletions

View File

@ -791,16 +791,15 @@ acorn.plugins.flow = function (instance) {
instance.extend("parseImportSpecifiers", function (inner) { instance.extend("parseImportSpecifiers", function (inner) {
return function (node) { return function (node) {
node.isType = false node.importKind = "value"
if (this.isContextual("type")) { var kind =
var start = this.markPosition() (this.type === tt._typeof ? "typeof" :
var typeId = this.parseIdent() (this.isContextual("type") ? "type" : null))
if ((this.type === tt.name && this.value !== "from") || this.type === tt.braceL || this.type === tt.star) { if (kind) {
node.isType = true var lh = this.lookahead()
} else { if ((lh.type === tt.name && lh.value !== "from") || lh.type === tt.braceL || lh.type === tt.star) {
node.specifiers.push(this.parseImportSpecifierDefault(typeId, start)) this.next()
if (this.isContextual("from")) return node.importKind = kind
this.eat(tt.comma)
} }
} }
inner.call(this, node) inner.call(this, node)

View File

@ -1,4 +1,4 @@
import {has, isArray} from "./util" import {has} from "./util"
import {SourceLocation} from "./location" import {SourceLocation} from "./location"
// A second optional argument can be given to further configure // A second optional argument can be given to further configure
@ -94,11 +94,11 @@ export function getOptions(opts) {
for (let opt in defaultOptions) for (let opt in defaultOptions)
options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt] options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt]
if (isArray(options.onToken)) { if (Array.isArray(options.onToken)) {
let tokens = options.onToken let tokens = options.onToken
options.onToken = (token) => tokens.push(token) options.onToken = (token) => tokens.push(token)
} }
if (isArray(options.onComment)) if (Array.isArray(options.onComment))
options.onComment = pushComment(options, options.onComment) options.onComment = pushComment(options, options.onComment)
return options return options

View File

@ -1,7 +1,3 @@
export function isArray(obj) {
return Object.prototype.toString.call(obj) === "[object Array]"
}
// Checks if an object has a property. // Checks if an object has a property.
export function has(obj, propName) { export function has(obj, propName) {