1 |
|
2 |
|
3 |
|
4 |
|
5 | "use strict";
|
6 |
|
7 | const RuntimeGlobals = require("../RuntimeGlobals");
|
8 | const Template = require("../Template");
|
9 | const HelperRuntimeModule = require("./HelperRuntimeModule");
|
10 |
|
11 | class DefinePropertyGettersRuntimeModule extends HelperRuntimeModule {
|
12 | constructor() {
|
13 | super("define property getters");
|
14 | }
|
15 |
|
16 | |
17 |
|
18 |
|
19 | generate() {
|
20 | const { runtimeTemplate } = this.compilation;
|
21 | const fn = RuntimeGlobals.definePropertyGetters;
|
22 | return Template.asString([
|
23 | "// define getter functions for harmony exports",
|
24 | `${fn} = ${runtimeTemplate.basicFunction("exports, definition", [
|
25 | `for(var key in definition) {`,
|
26 | Template.indent([
|
27 | `if(${RuntimeGlobals.hasOwnProperty}(definition, key) && !${RuntimeGlobals.hasOwnProperty}(exports, key)) {`,
|
28 | Template.indent([
|
29 | "Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });"
|
30 | ]),
|
31 | "}"
|
32 | ]),
|
33 | "}"
|
34 | ])};`
|
35 | ]);
|
36 | }
|
37 | }
|
38 |
|
39 | module.exports = DefinePropertyGettersRuntimeModule;
|