UNPKG

1.47 kBJavaScriptView Raw
1const HarmonyExportDependency = require('./harmony-export-dependency');
2const HarmonyImportDependency = require('./harmony-import-dependency');
3const HarmonyMarkerDependency = require('./harmony-marker-dependency');
4
5const PLUGIN_NAME = 'ClosureCompilerPlugin';
6
7class HarmonyParserPlugin {
8 apply(parser) {
9 parser.hooks.exportSpecifier.tap(
10 PLUGIN_NAME,
11 (statement, id, name, idx) => {
12 const dep = new HarmonyExportDependency(
13 statement.declaration,
14 statement.range,
15 parser.state.module,
16 id,
17 name
18 );
19 dep.loc = Object.create(statement.loc);
20 dep.loc.index = idx;
21 parser.state.current.addDependency(dep);
22 return true;
23 }
24 );
25
26 parser.hooks.exportImport.tap(PLUGIN_NAME, (statement) => {
27 parser.state.current.addDependency(
28 new HarmonyMarkerDependency(statement.range)
29 );
30 });
31
32 parser.hooks.import.tap('ClosureCompilerPlugin', (statement, source) => {
33 parser.state.current.addDependency(
34 new HarmonyMarkerDependency(statement.range)
35 );
36 const dep = new HarmonyImportDependency(
37 source,
38 parser.state.module,
39 parser.state.lastHarmonyImportOrder,
40 parser.state.harmonyParserScope,
41 null,
42 null,
43 statement.source.range
44 );
45 parser.state.current.addDependency(dep);
46 return true;
47 });
48 }
49}
50
51module.exports = HarmonyParserPlugin;