2
0
mirror of https://github.com/iconify/iconify.git synced 2024-09-19 16:59:02 +00:00

Do not use optional chaining in utils and core, some people still use old build tools that cannot parse it

This commit is contained in:
Vjacheslav Trushkin 2022-03-31 14:41:37 +03:00
parent 4540497953
commit fb537ef559
7 changed files with 334 additions and 16 deletions

View File

@ -44,7 +44,7 @@ interface WindowWithStorage extends Window {
try {
const w = (window || self) as unknown as WindowWithStorage | undefined;
if (w?._iconifyStorage.version === storageVersion) {
if (w && w._iconifyStorage.version === storageVersion) {
storage = w._iconifyStorage.storage;
}
} catch (err) {

View File

@ -11,6 +11,7 @@
"devDependencies": {
"@iconify/core": "^1.3.1",
"@microsoft/api-extractor": "^7.19.5",
"@rollup/plugin-buble": "^0.21.3",
"@rollup/plugin-node-resolve": "^13.1.3",
"@rollup/plugin-replace": "^4.0.0",
"@types/jest": "^27.4.1",
@ -2487,6 +2488,23 @@
"node": ">= 8"
}
},
"node_modules/@rollup/plugin-buble": {
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/@rollup/plugin-buble/-/plugin-buble-0.21.3.tgz",
"integrity": "sha512-Iv8cCuFPnMdqV4pcyU+OrfjOfagPArRQ1PyQjx5KgHk3dARedI+8PNTLSMpJts0lQJr8yF2pAU4GxpxCBJ9HYw==",
"dev": true,
"dependencies": {
"@rollup/pluginutils": "^3.0.8",
"@types/buble": "^0.19.2",
"buble": "^0.20.0"
},
"engines": {
"node": ">= 8.0.0"
},
"peerDependencies": {
"rollup": "^1.20.0||^2.0.0"
}
},
"node_modules/@rollup/plugin-node-resolve": {
"version": "13.1.3",
"resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-13.1.3.tgz",
@ -2670,6 +2688,15 @@
"@babel/types": "^7.3.0"
}
},
"node_modules/@types/buble": {
"version": "0.19.2",
"resolved": "https://registry.npmjs.org/@types/buble/-/buble-0.19.2.tgz",
"integrity": "sha512-uUD8zIfXMKThmFkahTXDGI3CthFH1kMg2dOm3KLi4GlC5cbARA64bEcUMbbWdWdE73eoc/iBB9PiTMqH0dNS2Q==",
"dev": true,
"dependencies": {
"magic-string": "^0.25.0"
}
},
"node_modules/@types/estree": {
"version": "0.0.39",
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz",
@ -3564,6 +3591,45 @@
"node-int64": "^0.4.0"
}
},
"node_modules/buble": {
"version": "0.20.0",
"resolved": "https://registry.npmjs.org/buble/-/buble-0.20.0.tgz",
"integrity": "sha512-/1gnaMQE8xvd5qsNBl+iTuyjJ9XxeaVxAMF86dQ4EyxFJOZtsgOS8Ra+7WHgZTam5IFDtt4BguN0sH0tVTKrOw==",
"dev": true,
"dependencies": {
"acorn": "^6.4.1",
"acorn-dynamic-import": "^4.0.0",
"acorn-jsx": "^5.2.0",
"chalk": "^2.4.2",
"magic-string": "^0.25.7",
"minimist": "^1.2.5",
"regexpu-core": "4.5.4"
},
"bin": {
"buble": "bin/buble"
}
},
"node_modules/buble/node_modules/acorn": {
"version": "6.4.2",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-6.4.2.tgz",
"integrity": "sha512-XtGIhXwF8YM8bJhGxG5kXgjkEuNGLTkoYqVE+KMR+aspr4KGYmKYg7yUe3KghyQ9yheNwLnjmzh/7+gfDBmHCQ==",
"dev": true,
"bin": {
"acorn": "bin/acorn"
},
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/buble/node_modules/acorn-dynamic-import": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/acorn-dynamic-import/-/acorn-dynamic-import-4.0.0.tgz",
"integrity": "sha512-d3OEjQV4ROpoflsnUA8HozoIR504TFxNivYEUi6uwz0IYhBkTDXGuWlNdMtybRt3nqVx/L6XqMt0FxkXuWKZhw==",
"dev": true,
"peerDependencies": {
"acorn": "^6.0.0"
}
},
"node_modules/buffer-from": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
@ -8928,6 +8994,24 @@
"integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==",
"dev": true
},
"node_modules/regenerate": {
"version": "1.4.2",
"resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.2.tgz",
"integrity": "sha512-zrceR/XhGYU/d/opr2EKO7aRHUeiBI8qjtfHqADTwZd6Szfy16la6kqD0MIUs5z5hx6AaKa+PixpPrR289+I0A==",
"dev": true
},
"node_modules/regenerate-unicode-properties": {
"version": "8.2.0",
"resolved": "https://registry.npmjs.org/regenerate-unicode-properties/-/regenerate-unicode-properties-8.2.0.tgz",
"integrity": "sha512-F9DjY1vKLo/tPePDycuH3dn9H1OTPIkVD9Kz4LODu+F2C75mgjAJ7x/gwy6ZcSNRAAkhNlJSOHRe8k3p+K9WhA==",
"dev": true,
"dependencies": {
"regenerate": "^1.4.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/regexpp": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.2.0.tgz",
@ -8940,6 +9024,50 @@
"url": "https://github.com/sponsors/mysticatea"
}
},
"node_modules/regexpu-core": {
"version": "4.5.4",
"resolved": "https://registry.npmjs.org/regexpu-core/-/regexpu-core-4.5.4.tgz",
"integrity": "sha512-BtizvGtFQKGPUcTy56o3nk1bGRp4SZOTYrDtGNlqCQufptV5IkkLN6Emw+yunAJjzf+C9FQFtvq7IoA3+oMYHQ==",
"dev": true,
"dependencies": {
"regenerate": "^1.4.0",
"regenerate-unicode-properties": "^8.0.2",
"regjsgen": "^0.5.0",
"regjsparser": "^0.6.0",
"unicode-match-property-ecmascript": "^1.0.4",
"unicode-match-property-value-ecmascript": "^1.1.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/regjsgen": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/regjsgen/-/regjsgen-0.5.2.tgz",
"integrity": "sha512-OFFT3MfrH90xIW8OOSyUrk6QHD5E9JOTeGodiJeBS3J6IwlgzJMNE/1bZklWz5oTg+9dCMyEetclvCVXOPoN3A==",
"dev": true
},
"node_modules/regjsparser": {
"version": "0.6.9",
"resolved": "https://registry.npmjs.org/regjsparser/-/regjsparser-0.6.9.tgz",
"integrity": "sha512-ZqbNRz1SNjLAiYuwY0zoXW8Ne675IX5q+YHioAGbCw4X96Mjl2+dcX9B2ciaeyYjViDAfvIjFpQjJgLttTEERQ==",
"dev": true,
"dependencies": {
"jsesc": "~0.5.0"
},
"bin": {
"regjsparser": "bin/parser"
}
},
"node_modules/regjsparser/node_modules/jsesc": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz",
"integrity": "sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0=",
"dev": true,
"bin": {
"jsesc": "bin/jsesc"
}
},
"node_modules/require-directory": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
@ -9596,6 +9724,46 @@
"node": ">=4.2.0"
}
},
"node_modules/unicode-canonical-property-names-ecmascript": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz",
"integrity": "sha512-jDrNnXWHd4oHiTZnx/ZG7gtUTVp+gCcTTKr8L0HjlwphROEW3+Him+IpvC+xcJEFegapiMZyZe02CyuOnRmbnQ==",
"dev": true,
"engines": {
"node": ">=4"
}
},
"node_modules/unicode-match-property-ecmascript": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/unicode-match-property-ecmascript/-/unicode-match-property-ecmascript-1.0.4.tgz",
"integrity": "sha512-L4Qoh15vTfntsn4P1zqnHulG0LdXgjSO035fEpdtp6YxXhMT51Q6vgM5lYdG/5X3MjS+k/Y9Xw4SFCY9IkR0rg==",
"dev": true,
"dependencies": {
"unicode-canonical-property-names-ecmascript": "^1.0.4",
"unicode-property-aliases-ecmascript": "^1.0.4"
},
"engines": {
"node": ">=4"
}
},
"node_modules/unicode-match-property-value-ecmascript": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/unicode-match-property-value-ecmascript/-/unicode-match-property-value-ecmascript-1.2.0.tgz",
"integrity": "sha512-wjuQHGQVofmSJv1uVISKLE5zO2rNGzM/KCYZch/QQvez7C1hUhBIuZ701fYXExuufJFMPhv2SyL8CyoIfMLbIQ==",
"dev": true,
"engines": {
"node": ">=4"
}
},
"node_modules/unicode-property-aliases-ecmascript": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/unicode-property-aliases-ecmascript/-/unicode-property-aliases-ecmascript-1.1.0.tgz",
"integrity": "sha512-PqSoPh/pWetQ2phoj5RLiaqIk4kCNwoV3CI+LfGmWLKI3rE3kl1h59XpX2BjgDrmbxD9ARtQobPGU1SguCYuQg==",
"dev": true,
"engines": {
"node": ">=4"
}
},
"node_modules/universalify": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
@ -11755,6 +11923,17 @@
"fastq": "^1.6.0"
}
},
"@rollup/plugin-buble": {
"version": "0.21.3",
"resolved": "https://registry.npmjs.org/@rollup/plugin-buble/-/plugin-buble-0.21.3.tgz",
"integrity": "sha512-Iv8cCuFPnMdqV4pcyU+OrfjOfagPArRQ1PyQjx5KgHk3dARedI+8PNTLSMpJts0lQJr8yF2pAU4GxpxCBJ9HYw==",
"dev": true,
"requires": {
"@rollup/pluginutils": "^3.0.8",
"@types/buble": "^0.19.2",
"buble": "^0.20.0"
}
},
"@rollup/plugin-node-resolve": {
"version": "13.1.3",
"resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-13.1.3.tgz",
@ -11921,6 +12100,15 @@
"@babel/types": "^7.3.0"
}
},
"@types/buble": {
"version": "0.19.2",
"resolved": "https://registry.npmjs.org/@types/buble/-/buble-0.19.2.tgz",
"integrity": "sha512-uUD8zIfXMKThmFkahTXDGI3CthFH1kMg2dOm3KLi4GlC5cbARA64bEcUMbbWdWdE73eoc/iBB9PiTMqH0dNS2Q==",
"dev": true,
"requires": {
"magic-string": "^0.25.0"
}
},
"@types/estree": {
"version": "0.0.39",
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz",
@ -12551,6 +12739,36 @@
"node-int64": "^0.4.0"
}
},
"buble": {
"version": "0.20.0",
"resolved": "https://registry.npmjs.org/buble/-/buble-0.20.0.tgz",
"integrity": "sha512-/1gnaMQE8xvd5qsNBl+iTuyjJ9XxeaVxAMF86dQ4EyxFJOZtsgOS8Ra+7WHgZTam5IFDtt4BguN0sH0tVTKrOw==",
"dev": true,
"requires": {
"acorn": "^6.4.1",
"acorn-dynamic-import": "^4.0.0",
"acorn-jsx": "^5.2.0",
"chalk": "^2.4.2",
"magic-string": "^0.25.7",
"minimist": "^1.2.5",
"regexpu-core": "4.5.4"
},
"dependencies": {
"acorn": {
"version": "6.4.2",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-6.4.2.tgz",
"integrity": "sha512-XtGIhXwF8YM8bJhGxG5kXgjkEuNGLTkoYqVE+KMR+aspr4KGYmKYg7yUe3KghyQ9yheNwLnjmzh/7+gfDBmHCQ==",
"dev": true
},
"acorn-dynamic-import": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/acorn-dynamic-import/-/acorn-dynamic-import-4.0.0.tgz",
"integrity": "sha512-d3OEjQV4ROpoflsnUA8HozoIR504TFxNivYEUi6uwz0IYhBkTDXGuWlNdMtybRt3nqVx/L6XqMt0FxkXuWKZhw==",
"dev": true,
"requires": {}
}
}
},
"buffer-from": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
@ -16544,12 +16762,64 @@
"integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==",
"dev": true
},
"regenerate": {
"version": "1.4.2",
"resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.2.tgz",
"integrity": "sha512-zrceR/XhGYU/d/opr2EKO7aRHUeiBI8qjtfHqADTwZd6Szfy16la6kqD0MIUs5z5hx6AaKa+PixpPrR289+I0A==",
"dev": true
},
"regenerate-unicode-properties": {
"version": "8.2.0",
"resolved": "https://registry.npmjs.org/regenerate-unicode-properties/-/regenerate-unicode-properties-8.2.0.tgz",
"integrity": "sha512-F9DjY1vKLo/tPePDycuH3dn9H1OTPIkVD9Kz4LODu+F2C75mgjAJ7x/gwy6ZcSNRAAkhNlJSOHRe8k3p+K9WhA==",
"dev": true,
"requires": {
"regenerate": "^1.4.0"
}
},
"regexpp": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.2.0.tgz",
"integrity": "sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg==",
"dev": true
},
"regexpu-core": {
"version": "4.5.4",
"resolved": "https://registry.npmjs.org/regexpu-core/-/regexpu-core-4.5.4.tgz",
"integrity": "sha512-BtizvGtFQKGPUcTy56o3nk1bGRp4SZOTYrDtGNlqCQufptV5IkkLN6Emw+yunAJjzf+C9FQFtvq7IoA3+oMYHQ==",
"dev": true,
"requires": {
"regenerate": "^1.4.0",
"regenerate-unicode-properties": "^8.0.2",
"regjsgen": "^0.5.0",
"regjsparser": "^0.6.0",
"unicode-match-property-ecmascript": "^1.0.4",
"unicode-match-property-value-ecmascript": "^1.1.0"
}
},
"regjsgen": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/regjsgen/-/regjsgen-0.5.2.tgz",
"integrity": "sha512-OFFT3MfrH90xIW8OOSyUrk6QHD5E9JOTeGodiJeBS3J6IwlgzJMNE/1bZklWz5oTg+9dCMyEetclvCVXOPoN3A==",
"dev": true
},
"regjsparser": {
"version": "0.6.9",
"resolved": "https://registry.npmjs.org/regjsparser/-/regjsparser-0.6.9.tgz",
"integrity": "sha512-ZqbNRz1SNjLAiYuwY0zoXW8Ne675IX5q+YHioAGbCw4X96Mjl2+dcX9B2ciaeyYjViDAfvIjFpQjJgLttTEERQ==",
"dev": true,
"requires": {
"jsesc": "~0.5.0"
},
"dependencies": {
"jsesc": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz",
"integrity": "sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0=",
"dev": true
}
}
},
"require-directory": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
@ -17013,6 +17283,34 @@
"integrity": "sha512-HM/hFigTBHZhLXshn9sN37H085+hQGeJHJ/X7LpBWLID/fbc2acUMfU+lGD98X81sKP+pFa9f0DZmCwB9GnbAg==",
"dev": true
},
"unicode-canonical-property-names-ecmascript": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz",
"integrity": "sha512-jDrNnXWHd4oHiTZnx/ZG7gtUTVp+gCcTTKr8L0HjlwphROEW3+Him+IpvC+xcJEFegapiMZyZe02CyuOnRmbnQ==",
"dev": true
},
"unicode-match-property-ecmascript": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/unicode-match-property-ecmascript/-/unicode-match-property-ecmascript-1.0.4.tgz",
"integrity": "sha512-L4Qoh15vTfntsn4P1zqnHulG0LdXgjSO035fEpdtp6YxXhMT51Q6vgM5lYdG/5X3MjS+k/Y9Xw4SFCY9IkR0rg==",
"dev": true,
"requires": {
"unicode-canonical-property-names-ecmascript": "^1.0.4",
"unicode-property-aliases-ecmascript": "^1.0.4"
}
},
"unicode-match-property-value-ecmascript": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/unicode-match-property-value-ecmascript/-/unicode-match-property-value-ecmascript-1.2.0.tgz",
"integrity": "sha512-wjuQHGQVofmSJv1uVISKLE5zO2rNGzM/KCYZch/QQvez7C1hUhBIuZ701fYXExuufJFMPhv2SyL8CyoIfMLbIQ==",
"dev": true
},
"unicode-property-aliases-ecmascript": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/unicode-property-aliases-ecmascript/-/unicode-property-aliases-ecmascript-1.1.0.tgz",
"integrity": "sha512-PqSoPh/pWetQ2phoj5RLiaqIk4kCNwoV3CI+LfGmWLKI3rE3kl1h59XpX2BjgDrmbxD9ARtQobPGU1SguCYuQg==",
"dev": true
},
"universalify": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",

View File

@ -71,6 +71,7 @@
"devDependencies": {
"@iconify/core": "^1.3.1",
"@microsoft/api-extractor": "^7.19.5",
"@rollup/plugin-buble": "^0.21.3",
"@rollup/plugin-node-resolve": "^13.1.3",
"@rollup/plugin-replace": "^4.0.0",
"@types/jest": "^27.4.1",

View File

@ -1,5 +1,6 @@
import { readFileSync, writeFileSync } from 'fs';
import resolve from '@rollup/plugin-node-resolve';
import buble from '@rollup/plugin-buble';
import { terser } from 'rollup-plugin-terser';
import replace from '@rollup/plugin-replace';
@ -122,6 +123,17 @@ names.forEach((name) => {
],
};
if (ext === 'js') {
// Support old browsers only in .js files.
// Other files are for modern browsers that don't need it or
// for bundlers that should handle old browser support themselves.
item.plugins.push(
buble({
objectAssign: 'Object.assign',
})
);
}
if (minify) {
item.plugins.push(terser());
}

View File

@ -33,8 +33,9 @@ export function getIconData(
}
// Check if alias exists
if (data.aliases?.[name] !== void 0) {
const item = data.aliases?.[name];
const aliases = data.aliases;
if (aliases && aliases[name] !== void 0) {
const item = aliases[name];
const result = getIcon(item.parent, iteration + 1);
if (result) {
return mergeIconData(result, item);
@ -43,8 +44,9 @@ export function getIconData(
}
// Check if character exists
if (iteration === 0 && data.chars?.[name] !== void 0) {
return getIcon(data.chars?.[name], iteration + 1);
const chars = data.chars;
if (!iteration && chars && chars[name] !== void 0) {
return getIcon(chars[name], iteration + 1);
}
return null;

View File

@ -39,20 +39,22 @@ export function getIcons(
}
// Check for alias
if (data.aliases?.[name] !== void 0) {
const copied = copy(data.aliases[name].parent, iteration + 1);
const aliases = data.aliases;
if (aliases && aliases[name] !== void 0) {
const copied = copy(aliases[name].parent, iteration + 1);
if (copied) {
if (result.aliases === void 0) {
result.aliases = Object.create(null) as never;
}
result.aliases[name] = { ...data.aliases[name] };
result.aliases[name] = { ...aliases[name] };
}
return copied;
}
// Check for character, return as alias
if (data.chars?.[name] !== void 0) {
const parent = data.chars?.[name];
const chars = data.chars;
if (chars && chars[name] !== void 0) {
const parent = chars[name];
const copied = copy(parent, iteration + 1);
if (copied) {
if (result.aliases === void 0) {

View File

@ -92,7 +92,7 @@ export function validateIconSet(
obj: unknown,
options?: IconSetValidationOptions
): IconifyJSON {
const fix = !!options?.fix;
const fix = !!(options && options.fix);
// Check for object with 'icons' nested object
if (
@ -108,7 +108,7 @@ export function validateIconSet(
const data = obj as IconifyJSON;
// Set or validate prefix
if (typeof options?.prefix === 'string') {
if (options && typeof options.prefix === 'string') {
data.prefix = options.prefix;
} else if (
typeof data.prefix !== 'string' ||
@ -118,7 +118,7 @@ export function validateIconSet(
}
// Set or validate provider
if (typeof options?.provider === 'string') {
if (options && typeof options.provider === 'string') {
data.provider = options.provider;
} else if (data.provider !== void 0) {
const value = data.provider;
@ -183,7 +183,10 @@ export function validateIconSet(
}
// Make sure icons list is not empty
if (!Object.keys(data.icons).length && !data.not_found?.length) {
if (
!Object.keys(data.icons).length &&
!(data.not_found && data.not_found.length)
) {
throw new Error('Icon set is empty');
}
@ -313,8 +316,8 @@ export function validateIconSet(
}
const target = chars[char];
if (
data.icons[target] === void 0 &&
data.aliases?.[target] === void 0
!data.icons[target] &&
(!data.aliases || !data.aliases[target])
) {
if (fix) {
delete chars[char];