-
Notifications
You must be signed in to change notification settings - Fork 2
/
babel-plugin-special-symbols.js
35 lines (32 loc) · 1.29 KB
/
babel-plugin-special-symbols.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
/**
* (1)plugin中@babel/plugin-transform-modules-commonjs("strictMode": false)是使babel编译完成之后不自动加上strict mode
* (2)Program:是即使你加上了strict mode 也会帮你干掉
* (1)的优先级大于(2)
*/
exports["default"] = function () {
return {
visitor: {
Program: {
exit: function exit(path) {
var list = path.node.directives;
for (var i = list.length - 1, it; i >= 0; i--) {
it = list[i];
if (it.value.value === 'use strict') {
list.splice(i, 1);
}
}
}
},
StringLiteral: (path, state) => {
if (path && path.node) {
path.node.value && (path.node.value = path.node.value.replace(/\$__\$/g, '\\'));
if (path.node.extra) {
path.node.extra.rawValue && ( path.node.extra.rawValue = path.node.extra.rawValue.replace(/\$__\$/g, '\\'));
path.node.extra.raw && ( path.node.extra.raw = path.node.extra.raw.replace(/\$__\$/g, '\\'));
}
}
},
}
};
};
module.exports = exports["default"];