source: trip-planner-front/node_modules/@babel/template/lib/options.js@ 8d391a1

Last change on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.0 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.merge = merge;
7exports.validate = validate;
8exports.normalizeReplacements = normalizeReplacements;
9
10function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
11
12function merge(a, b) {
13 const {
14 placeholderWhitelist = a.placeholderWhitelist,
15 placeholderPattern = a.placeholderPattern,
16 preserveComments = a.preserveComments,
17 syntacticPlaceholders = a.syntacticPlaceholders
18 } = b;
19 return {
20 parser: Object.assign({}, a.parser, b.parser),
21 placeholderWhitelist,
22 placeholderPattern,
23 preserveComments,
24 syntacticPlaceholders
25 };
26}
27
28function validate(opts) {
29 if (opts != null && typeof opts !== "object") {
30 throw new Error("Unknown template options.");
31 }
32
33 const _ref = opts || {},
34 {
35 placeholderWhitelist,
36 placeholderPattern,
37 preserveComments,
38 syntacticPlaceholders
39 } = _ref,
40 parser = _objectWithoutPropertiesLoose(_ref, ["placeholderWhitelist", "placeholderPattern", "preserveComments", "syntacticPlaceholders"]);
41
42 if (placeholderWhitelist != null && !(placeholderWhitelist instanceof Set)) {
43 throw new Error("'.placeholderWhitelist' must be a Set, null, or undefined");
44 }
45
46 if (placeholderPattern != null && !(placeholderPattern instanceof RegExp) && placeholderPattern !== false) {
47 throw new Error("'.placeholderPattern' must be a RegExp, false, null, or undefined");
48 }
49
50 if (preserveComments != null && typeof preserveComments !== "boolean") {
51 throw new Error("'.preserveComments' must be a boolean, null, or undefined");
52 }
53
54 if (syntacticPlaceholders != null && typeof syntacticPlaceholders !== "boolean") {
55 throw new Error("'.syntacticPlaceholders' must be a boolean, null, or undefined");
56 }
57
58 if (syntacticPlaceholders === true && (placeholderWhitelist != null || placeholderPattern != null)) {
59 throw new Error("'.placeholderWhitelist' and '.placeholderPattern' aren't compatible" + " with '.syntacticPlaceholders: true'");
60 }
61
62 return {
63 parser,
64 placeholderWhitelist: placeholderWhitelist || undefined,
65 placeholderPattern: placeholderPattern == null ? undefined : placeholderPattern,
66 preserveComments: preserveComments == null ? undefined : preserveComments,
67 syntacticPlaceholders: syntacticPlaceholders == null ? undefined : syntacticPlaceholders
68 };
69}
70
71function normalizeReplacements(replacements) {
72 if (Array.isArray(replacements)) {
73 return replacements.reduce((acc, replacement, i) => {
74 acc["$" + i] = replacement;
75 return acc;
76 }, {});
77 } else if (typeof replacements === "object" || replacements == null) {
78 return replacements || undefined;
79 }
80
81 throw new Error("Template replacements must be an array, object, null, or undefined");
82}
Note: See TracBrowser for help on using the repository browser.