main
Last change
on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 | /*
|
---|
2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
3 | Author Tobias Koppers @sokra
|
---|
4 | */
|
---|
5 |
|
---|
6 | "use strict";
|
---|
7 |
|
---|
8 | const SAFE_IDENTIFIER = /^[_a-zA-Z$][_a-zA-Z$0-9]*$/;
|
---|
9 | const RESERVED_IDENTIFIER = new Set([
|
---|
10 | "break",
|
---|
11 | "case",
|
---|
12 | "catch",
|
---|
13 | "class",
|
---|
14 | "const",
|
---|
15 | "continue",
|
---|
16 | "debugger",
|
---|
17 | "default",
|
---|
18 | "delete",
|
---|
19 | "do",
|
---|
20 | "else",
|
---|
21 | "export",
|
---|
22 | "extends",
|
---|
23 | "finally",
|
---|
24 | "for",
|
---|
25 | "function",
|
---|
26 | "if",
|
---|
27 | "import",
|
---|
28 | "in",
|
---|
29 | "instanceof",
|
---|
30 | "new",
|
---|
31 | "return",
|
---|
32 | "super",
|
---|
33 | "switch",
|
---|
34 | "this",
|
---|
35 | "throw",
|
---|
36 | "try",
|
---|
37 | "typeof",
|
---|
38 | "var",
|
---|
39 | "void",
|
---|
40 | "while",
|
---|
41 | "with",
|
---|
42 | "enum",
|
---|
43 | // strict mode
|
---|
44 | "implements",
|
---|
45 | "interface",
|
---|
46 | "let",
|
---|
47 | "package",
|
---|
48 | "private",
|
---|
49 | "protected",
|
---|
50 | "public",
|
---|
51 | "static",
|
---|
52 | "yield",
|
---|
53 | "yield",
|
---|
54 | // module code
|
---|
55 | "await",
|
---|
56 | // skip future reserved keywords defined under ES1 till ES3
|
---|
57 | // additional
|
---|
58 | "null",
|
---|
59 | "true",
|
---|
60 | "false"
|
---|
61 | ]);
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * @summary Returns a valid JS property name for the given property.
|
---|
65 | * Certain strings like "default", "null", and names with whitespace are not
|
---|
66 | * valid JS property names, so they are returned as strings.
|
---|
67 | * @param {string} prop property name to analyze
|
---|
68 | * @returns {string} valid JS property name
|
---|
69 | */
|
---|
70 | const propertyName = prop => {
|
---|
71 | if (SAFE_IDENTIFIER.test(prop) && !RESERVED_IDENTIFIER.has(prop)) {
|
---|
72 | return prop;
|
---|
73 | }
|
---|
74 | return JSON.stringify(prop);
|
---|
75 | };
|
---|
76 |
|
---|
77 | module.exports = { SAFE_IDENTIFIER, RESERVED_IDENTIFIER, propertyName };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.