UNPKG

1.4 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = buildExpressionTemplate;
7
8var _template = _interopRequireDefault(require("@babel/template"));
9
10var _invariant = _interopRequireDefault(require("../invariant.js"));
11
12function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
14/**
15 * Copyright (c) 2017-present, Facebook, Inc.
16 * All rights reserved.
17 *
18 * This source code is licensed under the BSD-style license found in the
19 * LICENSE file in the root directory of this source tree. An additional grant
20 * of patent rights can be found in the PATENTS file in the same directory.
21 */
22const placeholders = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
23const placeholderWhitelist = new Set(["global", ...placeholders]);
24
25function buildExpressionTemplate(code) {
26 let template;
27 return preludeGenerator => obj => {
28 if (template === undefined) template = (0, _template.default)(code, {
29 placeholderPattern: false,
30 placeholderWhitelist
31 });
32 if (preludeGenerator !== undefined && code.includes("global")) obj = Object.assign({
33 global: preludeGenerator.memoizeReference("global")
34 }, obj);
35 let result = template(obj).expression;
36 (0, _invariant.default)(result !== undefined, "Code does not represent an expression: " + code);
37 return result;
38 };
39}
40//# sourceMappingURL=builder.js.map
\No newline at end of file