-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.coffee
74 lines (74 loc) · 2.44 KB
/
index.coffee
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
module.exports = ({types}) ->
program = null
visitor:
Program: (path) ->
program = path
undefined
post: ->
## Prepend JavaScript code:
## require = ((r) =>
## Object.assign(
## (id) => (module.deps.push(r.resolve(id)), r(id)),
## r
## )
## )(require);
## The `Object.assign` copies over enumerable properties
## (`resolve`, `main`, `extensions`, `cache`) from the `require` object
## to the new function which pushes to `module.deps` and calls `require`.
program.unshiftContainer 'body',
types.expressionStatement types.assignmentExpression(
'='
types.identifier 'require'
types.callExpression(
types.arrowFunctionExpression(
[types.identifier 'r']
types.callExpression(
types.memberExpression(
types.identifier 'Object'
types.identifier 'assign'
)
[
types.arrowFunctionExpression(
[types.identifier 'id']
types.sequenceExpression [
types.callExpression(
types.memberExpression(
types.memberExpression(
types.identifier 'module'
types.identifier 'deps'
)
types.identifier 'push'
)
[types.callExpression(
types.memberExpression(
types.identifier 'r'
types.identifier 'resolve'
)
[types.identifier 'id']
)]
)
types.callExpression(
types.identifier 'r'
[types.identifier 'id']
)
]
)
types.identifier 'r'
]
)
)
[types.identifier 'require']
)
)
## Prepend JavaScript code: module.deps = [];
## Because this gets prepended last, it ends up being the first line.
program.unshiftContainer 'body',
types.expressionStatement types.assignmentExpression(
'='
types.memberExpression(
types.identifier 'module'
types.identifier 'deps'
)
types.arrayExpression()
)
undefined