-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathindex.js
146 lines (122 loc) · 3.71 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
'use strict';
const VersionChecker = require('ember-cli-version-checker');
module.exports = {
name: 'ember-angle-bracket-invocation-polyfill',
init() {
this._super.init && this._super.init.apply(this, arguments);
let checker = new VersionChecker(this.project);
let emberVersion = checker.forEmber();
this.shouldPolyfill = emberVersion.lt('3.5.0-alpha.1');
this.shouldPolyfillNested = emberVersion.lt('3.10.0-alpha.1');
this.shouldPolyfillBuiltinComponents = emberVersion.lt('3.10.0-alpha.1');
let parentChecker = new VersionChecker(this.parent);
let precompileVersion = parentChecker.for('ember-cli-htmlbars-inline-precompile');
if (precompileVersion.exists() && precompileVersion.lt('1.0.3')) {
this.ui.writeWarnLine(
'Detected a version of ember-cli-htmlbars-inline-precompile that does not' +
' support angle bracket invocation, please update to at least 1.0.3.'
);
}
},
setupPreprocessorRegistry(type, registry) {
if (this.shouldPolyfill) {
let pluginObj = this._buildPlugin();
pluginObj.parallelBabel = {
requireFile: __filename,
buildUsing: '_buildPlugin',
params: {},
};
registry.add('htmlbars-ast-plugin', pluginObj);
} else if (this.shouldPolyfillNested) {
let pluginObj = this._buildNestedPlugin();
pluginObj.parallelBabel = {
requireFile: __filename,
buildUsing: '_buildPlugin',
params: {},
};
registry.add('htmlbars-ast-plugin', pluginObj);
}
if (this.shouldPolyfillBuiltinComponents) {
let linktoPluginObj = this._buildLinkToPlugin();
linktoPluginObj.parallelBabel = {
requireFile: __filename,
buildUsing: '_buildLinkToPlugin',
params: {},
};
registry.add('htmlbars-ast-plugin', linktoPluginObj);
let inputPluginObj = this._buildInputPlugin();
inputPluginObj.parallelBabel = {
requireFile: __filename,
buildUsing: '_buildInputPlugin',
params: {},
};
registry.add('htmlbars-ast-plugin', inputPluginObj);
}
},
_buildPlugin() {
return {
name: 'component-attributes',
plugin: require('./lib/ast-transform'),
baseDir() {
return __dirname;
},
};
},
_buildNestedPlugin() {
return {
name: 'nested-component-invocation-support',
plugin: require('./lib/ast-nested-transform'),
baseDir() {
return __dirname;
},
};
},
_buildLinkToPlugin() {
return {
name: 'link-to-component-invocation-support',
plugin: require('./lib/ast-link-to-transform'),
baseDir() {
return __dirname;
},
};
},
_buildInputPlugin() {
return {
name: 'input-component-invocation-support',
plugin: require('./lib/ast-input-transform'),
baseDir() {
return __dirname;
},
};
},
included() {
this._super.included.apply(this, arguments);
if (!this.shouldPolyfill) {
return;
}
this.import('vendor/angle-bracket-invocation-polyfill/runtime-polyfill.js');
},
treeForVendor(rawVendorTree) {
if (!this.shouldPolyfill) {
return;
}
let babelAddon = this.addons.find(addon => addon.name === 'ember-cli-babel');
let transpiledVendorTree = babelAddon.transpileTree(rawVendorTree, {
babel: this.options.babel,
'ember-cli-babel': {
compileModules: false,
},
});
return transpiledVendorTree;
},
treeForAddon() {
if (this.shouldPolyfillBuiltinComponents) {
return this._super.treeForAddon.apply(this, arguments);
}
},
treeForApp() {
if (this.shouldPolyfillBuiltinComponents) {
return this._super.treeForApp.apply(this, arguments);
}
},
};