Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
Merge branch 'giltayar-esm-support'
Browse files Browse the repository at this point in the history
  • Loading branch information
searls committed May 9, 2020
2 parents bcd39f1 + e582c79 commit 4bcdf40
Show file tree
Hide file tree
Showing 5 changed files with 2,127 additions and 5 deletions.
58 changes: 58 additions & 0 deletions index-esm.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
var assert = require('assert')
var _ = require('lodash')
var fs = require('fs')

var subject = require('./index')

module.exports = function () {
var source = fs.readFileSync('test/fixtures/esm.js').toString()

_.each({
1: [],
2: [],
3: ['a'],
4: ['a'],
5: ['a'],
6: ['z', 'b'],
7: ['z', 'b'],
8: ['z', 'b'],
9: ['c'],
10: [],
11: [],
12: ['d'],
13: ['d'],
14: ['d'],
15: [],
16: ['e'],
17: ['e'],
18: ['e'],
19: [],
20: [], // Would be cool if this worked, but I can't imagine how: ['e', 'f'],
21: [],
22: ['h', 'g'],
23: ['h', 'g'],
24: ['h', 'g'],
25: [],
26: ['i'],
27: ['i'],
28: ['i'],
29: [],
30: ['j'],
31: ['k', 'j'],
32: ['k', 'j'],
33: ['k', 'j'],
34: ['j'],
35: [],
36: [],
37: ['m', 'l']
}, function (expected, lineNumber) {
var result = subject(source, parseInt(lineNumber, 10))

try {
assert.deepEqual(result, expected)
} catch (e) {
console.error('Assertion for line ' + lineNumber + ' failed!')
throw e
}
})
}
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var acorn = require('acorn')
var walk = require('acorn/dist/walk')
var walk = require('acorn-walk')

module.exports = function (source, lineNumber) {
var ast = acorn.parse(source, {locations: true})
var ast = acorn.parse(source, {locations: true, sourceType: 'module'})
return functionNamesAtLineNumber(ast, lineNumber)
}

Expand Down
Loading

0 comments on commit 4bcdf40

Please sign in to comment.