@formatjs/icu-messageformat-parser
Advanced tools
Comparing version 2.9.8 to 2.10.0
@@ -7,1 +7,2 @@ import { Parser, ParserOptions } from './parser'; | ||
export declare const _Parser: typeof Parser; | ||
export { isStructurallySame } from './manipulator'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports._Parser = void 0; | ||
exports.isStructurallySame = exports._Parser = void 0; | ||
exports.parse = parse; | ||
@@ -50,1 +50,3 @@ var tslib_1 = require("tslib"); | ||
exports._Parser = parser_1.Parser; | ||
var manipulator_1 = require("./manipulator"); | ||
Object.defineProperty(exports, "isStructurallySame", { enumerable: true, get: function () { return manipulator_1.isStructurallySame; } }); |
@@ -7,1 +7,2 @@ import { Parser, ParserOptions } from './parser'; | ||
export declare const _Parser: typeof Parser; | ||
export { isStructurallySame } from './manipulator'; |
@@ -46,1 +46,2 @@ import { __assign } from "tslib"; | ||
export var _Parser = Parser; | ||
export { isStructurallySame } from './manipulator'; |
@@ -14,1 +14,2 @@ import { MessageFormatElement } from './types'; | ||
export declare function hoistSelectors(ast: MessageFormatElement[]): MessageFormatElement[]; | ||
export declare function isStructurallySame(a: MessageFormatElement[], b: MessageFormatElement[]): boolean; |
import { __spreadArray } from "tslib"; | ||
import { isPluralElement, isSelectElement, isTagElement, } from './types'; | ||
import { isArgumentElement, isDateElement, isLiteralElement, isNumberElement, isPluralElement, isPoundElement, isSelectElement, isTagElement, isTimeElement, } from './types'; | ||
function cloneDeep(obj) { | ||
@@ -68,1 +68,91 @@ if (Array.isArray(obj)) { | ||
} | ||
function isStructurallySamePluralOrSelect(el1, el2) { | ||
var options1 = el1.options; | ||
var options2 = el2.options; | ||
if (Object.keys(options1).length !== Object.keys(options2).length) { | ||
return false; | ||
} | ||
for (var key in options1) { | ||
if (!options2[key]) { | ||
return false; | ||
} | ||
if (!isStructurallySame(options1[key].value, options2[key].value)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
export function isStructurallySame(a, b) { | ||
var aWithoutLiteral = a.filter(function (el) { return !isLiteralElement(el); }); | ||
var bWithoutLiteral = b.filter(function (el) { return !isLiteralElement(el); }); | ||
if (aWithoutLiteral.length !== bWithoutLiteral.length) { | ||
return false; | ||
} | ||
var elementsMapInA = aWithoutLiteral.reduce(function (all, el) { | ||
if (isPoundElement(el)) { | ||
all['#'] = el; | ||
return all; | ||
} | ||
all[el.value] = el; | ||
return all; | ||
}, {}); | ||
var elementsMapInB = bWithoutLiteral.reduce(function (all, el) { | ||
if (isPoundElement(el)) { | ||
all['#'] = el; | ||
return all; | ||
} | ||
all[el.value] = el; | ||
return all; | ||
}, {}); | ||
for (var _i = 0, _a = Object.keys(elementsMapInA); _i < _a.length; _i++) { | ||
var varName = _a[_i]; | ||
var elA = elementsMapInA[varName]; | ||
var elB = elementsMapInB[varName]; | ||
if (!elB) { | ||
return false; | ||
} | ||
if (elA.type !== elB.type) { | ||
return false; | ||
} | ||
if (isLiteralElement(elA) || isLiteralElement(elB)) { | ||
continue; | ||
} | ||
if (isArgumentElement(elA) && | ||
isArgumentElement(elB) && | ||
elA.value !== elB.value) { | ||
return false; | ||
} | ||
if (isPoundElement(elA) || isPoundElement(elB)) { | ||
continue; | ||
} | ||
if (isDateElement(elA) || | ||
isTimeElement(elA) || | ||
isNumberElement(elA) || | ||
isDateElement(elB) || | ||
isTimeElement(elB) || | ||
isNumberElement(elB)) { | ||
if (elA.value !== elB.value) { | ||
return false; | ||
} | ||
} | ||
if (isPluralElement(elA) && | ||
isPluralElement(elB) && | ||
!isStructurallySamePluralOrSelect(elA, elB)) { | ||
return false; | ||
} | ||
if (isSelectElement(elA) && | ||
isSelectElement(elB) && | ||
isStructurallySamePluralOrSelect(elA, elB)) { | ||
return false; | ||
} | ||
if (isTagElement(elA) && isTagElement(elB)) { | ||
if (elA.value !== elB.value) { | ||
return false; | ||
} | ||
if (!isStructurallySame(elA.children, elB.children)) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} |
export declare function parse(): void; | ||
export * from './types'; | ||
export declare const _Parser: undefined; | ||
export { isStructurallySame } from './manipulator'; |
@@ -6,1 +6,2 @@ export function parse() { | ||
export var _Parser = undefined; | ||
export { isStructurallySame } from './manipulator'; |
@@ -65,7 +65,4 @@ import type { NumberFormatOptions } from '@formatjs/ecma402-abstract'; | ||
export type ArgumentElement = BaseElement<TYPE.argument>; | ||
export interface TagElement { | ||
type: TYPE.tag; | ||
value: string; | ||
export interface TagElement extends BaseElement<TYPE.tag> { | ||
children: MessageFormatElement[]; | ||
location?: Location; | ||
} | ||
@@ -72,0 +69,0 @@ export interface SimpleFormatElement<T extends TYPE, S extends Skeleton> extends BaseElement<T> { |
@@ -14,1 +14,2 @@ import { MessageFormatElement } from './types'; | ||
export declare function hoistSelectors(ast: MessageFormatElement[]): MessageFormatElement[]; | ||
export declare function isStructurallySame(a: MessageFormatElement[], b: MessageFormatElement[]): boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.hoistSelectors = hoistSelectors; | ||
exports.isStructurallySame = isStructurallySame; | ||
var tslib_1 = require("tslib"); | ||
@@ -71,1 +72,91 @@ var types_1 = require("./types"); | ||
} | ||
function isStructurallySamePluralOrSelect(el1, el2) { | ||
var options1 = el1.options; | ||
var options2 = el2.options; | ||
if (Object.keys(options1).length !== Object.keys(options2).length) { | ||
return false; | ||
} | ||
for (var key in options1) { | ||
if (!options2[key]) { | ||
return false; | ||
} | ||
if (!isStructurallySame(options1[key].value, options2[key].value)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
function isStructurallySame(a, b) { | ||
var aWithoutLiteral = a.filter(function (el) { return !(0, types_1.isLiteralElement)(el); }); | ||
var bWithoutLiteral = b.filter(function (el) { return !(0, types_1.isLiteralElement)(el); }); | ||
if (aWithoutLiteral.length !== bWithoutLiteral.length) { | ||
return false; | ||
} | ||
var elementsMapInA = aWithoutLiteral.reduce(function (all, el) { | ||
if ((0, types_1.isPoundElement)(el)) { | ||
all['#'] = el; | ||
return all; | ||
} | ||
all[el.value] = el; | ||
return all; | ||
}, {}); | ||
var elementsMapInB = bWithoutLiteral.reduce(function (all, el) { | ||
if ((0, types_1.isPoundElement)(el)) { | ||
all['#'] = el; | ||
return all; | ||
} | ||
all[el.value] = el; | ||
return all; | ||
}, {}); | ||
for (var _i = 0, _a = Object.keys(elementsMapInA); _i < _a.length; _i++) { | ||
var varName = _a[_i]; | ||
var elA = elementsMapInA[varName]; | ||
var elB = elementsMapInB[varName]; | ||
if (!elB) { | ||
return false; | ||
} | ||
if (elA.type !== elB.type) { | ||
return false; | ||
} | ||
if ((0, types_1.isLiteralElement)(elA) || (0, types_1.isLiteralElement)(elB)) { | ||
continue; | ||
} | ||
if ((0, types_1.isArgumentElement)(elA) && | ||
(0, types_1.isArgumentElement)(elB) && | ||
elA.value !== elB.value) { | ||
return false; | ||
} | ||
if ((0, types_1.isPoundElement)(elA) || (0, types_1.isPoundElement)(elB)) { | ||
continue; | ||
} | ||
if ((0, types_1.isDateElement)(elA) || | ||
(0, types_1.isTimeElement)(elA) || | ||
(0, types_1.isNumberElement)(elA) || | ||
(0, types_1.isDateElement)(elB) || | ||
(0, types_1.isTimeElement)(elB) || | ||
(0, types_1.isNumberElement)(elB)) { | ||
if (elA.value !== elB.value) { | ||
return false; | ||
} | ||
} | ||
if ((0, types_1.isPluralElement)(elA) && | ||
(0, types_1.isPluralElement)(elB) && | ||
!isStructurallySamePluralOrSelect(elA, elB)) { | ||
return false; | ||
} | ||
if ((0, types_1.isSelectElement)(elA) && | ||
(0, types_1.isSelectElement)(elB) && | ||
isStructurallySamePluralOrSelect(elA, elB)) { | ||
return false; | ||
} | ||
if ((0, types_1.isTagElement)(elA) && (0, types_1.isTagElement)(elB)) { | ||
if (elA.value !== elB.value) { | ||
return false; | ||
} | ||
if (!isStructurallySame(elA.children, elB.children)) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} |
export declare function parse(): void; | ||
export * from './types'; | ||
export declare const _Parser: undefined; | ||
export { isStructurallySame } from './manipulator'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports._Parser = void 0; | ||
exports.isStructurallySame = exports._Parser = void 0; | ||
exports.parse = parse; | ||
@@ -11,1 +11,3 @@ var tslib_1 = require("tslib"); | ||
exports._Parser = undefined; | ||
var manipulator_1 = require("./manipulator"); | ||
Object.defineProperty(exports, "isStructurallySame", { enumerable: true, get: function () { return manipulator_1.isStructurallySame; } }); |
{ | ||
"name": "@formatjs/icu-messageformat-parser", | ||
"version": "2.9.8", | ||
"version": "2.10.0", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "module": "lib/index.js", |
@@ -65,7 +65,4 @@ import type { NumberFormatOptions } from '@formatjs/ecma402-abstract'; | ||
export type ArgumentElement = BaseElement<TYPE.argument>; | ||
export interface TagElement { | ||
type: TYPE.tag; | ||
value: string; | ||
export interface TagElement extends BaseElement<TYPE.tag> { | ||
children: MessageFormatElement[]; | ||
location?: Location; | ||
} | ||
@@ -72,0 +69,0 @@ export interface SimpleFormatElement<T extends TYPE, S extends Skeleton> extends BaseElement<T> { |
208558
7293
74
2
6
1
16