-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
105 lines (90 loc) · 2.55 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
var test = require('tape')
var acorn = require('../')
var walk = require('../walk')
var baseAcorn = require('acorn')
test('parses object spread syntax', function (t) {
var ast = acorn.parse('var a = { ...b }')
t.equal(ast.body[0].declarations[0].init.type, 'ObjectExpression')
t.equal(ast.body[0].declarations[0].init.properties[0].type, 'SpreadElement')
ast = acorn.parse('function a ({ ...b }) {}')
t.equal(ast.body[0].params[0].type, 'ObjectPattern')
t.equal(ast.body[0].params[0].properties[0].type, 'RestElement')
t.end()
})
test('does not change main acorn module', function (t) {
t.throws(function () {
baseAcorn.parse('var a = { ...b }')
})
t.end()
})
test('tokenizes object spread syntax', function (t) {
var tokenizer = acorn.tokenizer('var a = { ...b }')
t.doesNotThrow(function (t) {
while (tokenizer.getToken().type !== acorn.tokTypes.eof) {}
})
t.end()
})
test('allows hashbangs by default', function (t) {
t.doesNotThrow(function () {
acorn.parse('#!/usr/bin/env node\nconsole.log("ok")')
})
t.end()
})
test('allows top level return by default', function (t) {
t.doesNotThrow(function () {
acorn.parse('console.log("ok"); return; console.log("not ok")')
})
t.end()
})
test('supports async generators', function (t) {
t.doesNotThrow(function () {
acorn.parse('async function* a () { await x; yield 1 }')
})
t.end()
})
test('supports async iteration', function (t) {
t.doesNotThrow(function () {
acorn.parse('async function l (y) { for await (const x of y) {} }')
})
t.end()
})
test('supports optional catch', function (t) {
t.doesNotThrow(function () {
acorn.parse('try { throw null } catch {}')
})
t.end()
})
test.skip('supports bigint', function (t) {
t.doesNotThrow(function () {
acorn.parse('50n ** 50n')
})
t.end()
})
test('supports import.meta with sourceType: module', function (t) {
t.doesNotThrow(function () {
acorn.parse('console.log(import.meta.url)', { sourceType: 'module' })
})
t.end()
})
test('supports dynamic import() with sourceType: module', function (t) {
t.doesNotThrow(function () {
acorn.parse('import("./whatever.mjs")', { sourceType: 'module' })
})
t.end()
})
test('walk supports plugin syntax', function (t) {
var ast = acorn.parse(
'async function* a() { try { await import(xyz); } catch { for await (x of null) {} } yield import.meta.url }',
{ sourceType: 'module' }
)
t.plan(2)
walk.simple(ast, {
Import () {
t.pass('import()')
},
MetaProperty () {
t.pass('import.meta')
}
})
t.end()
})