Commit 4e362378 authored by Rosanny Sihombing's avatar Rosanny Sihombing
Browse files

Merge branch 'MLAB-671' into 'testing'

Mlab 671

See merge request !158
parents 3d0c87b0 bde9ccfd
Pipeline #6646 passed with stage
in 11 seconds
{
"name": "@jridgewell/gen-mapping",
"version": "0.3.2",
"description": "Generate source maps",
"keywords": [
"source",
"map"
],
"author": "Justin Ridgewell <justin@ridgewell.name>",
"license": "MIT",
"repository": "https://github.com/jridgewell/gen-mapping",
"main": "dist/gen-mapping.umd.js",
"module": "dist/gen-mapping.mjs",
"typings": "dist/types/gen-mapping.d.ts",
"exports": {
".": [
{
"types": "./dist/types/gen-mapping.d.ts",
"browser": "./dist/gen-mapping.umd.js",
"require": "./dist/gen-mapping.umd.js",
"import": "./dist/gen-mapping.mjs"
},
"./dist/gen-mapping.umd.js"
],
"./package.json": "./package.json"
},
"files": [
"dist",
"src"
],
"engines": {
"node": ">=6.0.0"
},
"scripts": {
"benchmark": "run-s build:rollup benchmark:*",
"benchmark:install": "cd benchmark && npm install",
"benchmark:only": "node benchmark/index.mjs",
"prebuild": "rm -rf dist",
"build": "run-s -n build:*",
"build:rollup": "rollup -c rollup.config.js",
"build:ts": "tsc --project tsconfig.build.json",
"lint": "run-s -n lint:*",
"lint:prettier": "npm run test:lint:prettier -- --write",
"lint:ts": "npm run test:lint:ts -- --fix",
"pretest": "run-s build:rollup",
"test": "run-s -n test:lint test:coverage",
"test:debug": "mocha --inspect-brk",
"test:lint": "run-s -n test:lint:*",
"test:lint:prettier": "prettier --check '{src,test}/**/*.ts'",
"test:lint:ts": "eslint '{src,test}/**/*.ts'",
"test:only": "mocha",
"test:coverage": "c8 mocha",
"test:watch": "run-p 'build:rollup -- --watch' 'test:only -- --watch'",
"prepublishOnly": "npm run preversion",
"preversion": "run-s test build"
},
"devDependencies": {
"@rollup/plugin-typescript": "8.3.2",
"@types/mocha": "9.1.1",
"@types/node": "17.0.29",
"@typescript-eslint/eslint-plugin": "5.21.0",
"@typescript-eslint/parser": "5.21.0",
"benchmark": "2.1.4",
"c8": "7.11.2",
"eslint": "8.14.0",
"eslint-config-prettier": "8.5.0",
"mocha": "9.2.2",
"npm-run-all": "4.1.5",
"prettier": "2.6.2",
"rollup": "2.70.2",
"typescript": "4.6.3"
},
"dependencies": {
"@jridgewell/set-array": "^1.0.1",
"@jridgewell/sourcemap-codec": "^1.4.10",
"@jridgewell/trace-mapping": "^0.3.9"
}
}
import { SetArray, put } from '@jridgewell/set-array';
import { encode } from '@jridgewell/sourcemap-codec';
import { TraceMap, decodedMappings } from '@jridgewell/trace-mapping';
import {
COLUMN,
SOURCES_INDEX,
SOURCE_LINE,
SOURCE_COLUMN,
NAMES_INDEX,
} from './sourcemap-segment';
import type { SourceMapInput } from '@jridgewell/trace-mapping';
import type { SourceMapSegment } from './sourcemap-segment';
import type { DecodedSourceMap, EncodedSourceMap, Pos, Mapping } from './types';
export type { DecodedSourceMap, EncodedSourceMap, Mapping };
export type Options = {
file?: string | null;
sourceRoot?: string | null;
};
const NO_NAME = -1;
/**
* A low-level API to associate a generated position with an original source position. Line and
* column here are 0-based, unlike `addMapping`.
*/
export let addSegment: {
(
map: GenMapping,
genLine: number,
genColumn: number,
source?: null,
sourceLine?: null,
sourceColumn?: null,
name?: null,
content?: null,
): void;
(
map: GenMapping,
genLine: number,
genColumn: number,
source: string,
sourceLine: number,
sourceColumn: number,
name?: null,
content?: string | null,
): void;
(
map: GenMapping,
genLine: number,
genColumn: number,
source: string,
sourceLine: number,
sourceColumn: number,
name: string,
content?: string | null,
): void;
};
/**
* A high-level API to associate a generated position with an original source position. Line is
* 1-based, but column is 0-based, due to legacy behavior in `source-map` library.
*/
export let addMapping: {
(
map: GenMapping,
mapping: {
generated: Pos;
source?: null;
original?: null;
name?: null;
content?: null;
},
): void;
(
map: GenMapping,
mapping: {
generated: Pos;
source: string;
original: Pos;
name?: null;
content?: string | null;
},
): void;
(
map: GenMapping,
mapping: {
generated: Pos;
source: string;
original: Pos;
name: string;
content?: string | null;
},
): void;
};
/**
* Same as `addSegment`, but will only add the segment if it generates useful information in the
* resulting map. This only works correctly if segments are added **in order**, meaning you should
* not add a segment with a lower generated line/column than one that came before.
*/
export let maybeAddSegment: typeof addSegment;
/**
* Same as `addMapping`, but will only add the mapping if it generates useful information in the
* resulting map. This only works correctly if mappings are added **in order**, meaning you should
* not add a mapping with a lower generated line/column than one that came before.
*/
export let maybeAddMapping: typeof addMapping;
/**
* Adds/removes the content of the source file to the source map.
*/
export let setSourceContent: (map: GenMapping, source: string, content: string | null) => void;
/**
* Returns a sourcemap object (with decoded mappings) suitable for passing to a library that expects
* a sourcemap, or to JSON.stringify.
*/
export let toDecodedMap: (map: GenMapping) => DecodedSourceMap;
/**
* Returns a sourcemap object (with encoded mappings) suitable for passing to a library that expects
* a sourcemap, or to JSON.stringify.
*/
export let toEncodedMap: (map: GenMapping) => EncodedSourceMap;
/**
* Constructs a new GenMapping, using the already present mappings of the input.
*/
export let fromMap: (input: SourceMapInput) => GenMapping;
/**
* Returns an array of high-level mapping objects for every recorded segment, which could then be
* passed to the `source-map` library.
*/
export let allMappings: (map: GenMapping) => Mapping[];
// This split declaration is only so that terser can elminiate the static initialization block.
let addSegmentInternal: <S extends string | null | undefined>(
skipable: boolean,
map: GenMapping,
genLine: number,
genColumn: number,
source: S,
sourceLine: S extends string ? number : null | undefined,
sourceColumn: S extends string ? number : null | undefined,
name: S extends string ? string | null | undefined : null | undefined,
content: S extends string ? string | null | undefined : null | undefined,
) => void;
/**
* Provides the state to generate a sourcemap.
*/
export class GenMapping {
private _names = new SetArray();
private _sources = new SetArray();
private _sourcesContent: (string | null)[] = [];
private _mappings: SourceMapSegment[][] = [];
declare file: string | null | undefined;
declare sourceRoot: string | null | undefined;
constructor({ file, sourceRoot }: Options = {}) {
this.file = file;
this.sourceRoot = sourceRoot;
}
static {
addSegment = (map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) => {
return addSegmentInternal(
false,
map,
genLine,
genColumn,
source,
sourceLine,
sourceColumn,
name,
content,
);
};
maybeAddSegment = (
map,
genLine,
genColumn,
source,
sourceLine,
sourceColumn,
name,
content,
) => {
return addSegmentInternal(
true,
map,
genLine,
genColumn,
source,
sourceLine,
sourceColumn,
name,
content,
);
};
addMapping = (map, mapping) => {
return addMappingInternal(false, map, mapping as Parameters<typeof addMappingInternal>[2]);
};
maybeAddMapping = (map, mapping) => {
return addMappingInternal(true, map, mapping as Parameters<typeof addMappingInternal>[2]);
};
setSourceContent = (map, source, content) => {
const { _sources: sources, _sourcesContent: sourcesContent } = map;
sourcesContent[put(sources, source)] = content;
};
toDecodedMap = (map) => {
const {
file,
sourceRoot,
_mappings: mappings,
_sources: sources,
_sourcesContent: sourcesContent,
_names: names,
} = map;
removeEmptyFinalLines(mappings);
return {
version: 3,
file: file || undefined,
names: names.array,
sourceRoot: sourceRoot || undefined,
sources: sources.array,
sourcesContent,
mappings,
};
};
toEncodedMap = (map) => {
const decoded = toDecodedMap(map);
return {
...decoded,
mappings: encode(decoded.mappings as SourceMapSegment[][]),
};
};
allMappings = (map) => {
const out: Mapping[] = [];
const { _mappings: mappings, _sources: sources, _names: names } = map;
for (let i = 0; i < mappings.length; i++) {
const line = mappings[i];
for (let j = 0; j < line.length; j++) {
const seg = line[j];
const generated = { line: i + 1, column: seg[COLUMN] };
let source: string | undefined = undefined;
let original: Pos | undefined = undefined;
let name: string | undefined = undefined;
if (seg.length !== 1) {
source = sources.array[seg[SOURCES_INDEX]];
original = { line: seg[SOURCE_LINE] + 1, column: seg[SOURCE_COLUMN] };
if (seg.length === 5) name = names.array[seg[NAMES_INDEX]];
}
out.push({ generated, source, original, name } as Mapping);
}
}
return out;
};
fromMap = (input) => {
const map = new TraceMap(input);
const gen = new GenMapping({ file: map.file, sourceRoot: map.sourceRoot });
putAll(gen._names, map.names);
putAll(gen._sources, map.sources as string[]);
gen._sourcesContent = map.sourcesContent || map.sources.map(() => null);
gen._mappings = decodedMappings(map) as GenMapping['_mappings'];
return gen;
};
// Internal helpers
addSegmentInternal = (
skipable,
map,
genLine,
genColumn,
source,
sourceLine,
sourceColumn,
name,
content,
) => {
const {
_mappings: mappings,
_sources: sources,
_sourcesContent: sourcesContent,
_names: names,
} = map;
const line = getLine(mappings, genLine);
const index = getColumnIndex(line, genColumn);
if (!source) {
if (skipable && skipSourceless(line, index)) return;
return insert(line, index, [genColumn]);
}
// Sigh, TypeScript can't figure out sourceLine and sourceColumn aren't nullish if source
// isn't nullish.
assert<number>(sourceLine);
assert<number>(sourceColumn);
const sourcesIndex = put(sources, source);
const namesIndex = name ? put(names, name) : NO_NAME;
if (sourcesIndex === sourcesContent.length) sourcesContent[sourcesIndex] = content ?? null;
if (skipable && skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex)) {
return;
}
return insert(
line,
index,
name
? [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex]
: [genColumn, sourcesIndex, sourceLine, sourceColumn],
);
};
}
}
function assert<T>(_val: unknown): asserts _val is T {
// noop.
}
function getLine(mappings: SourceMapSegment[][], index: number): SourceMapSegment[] {
for (let i = mappings.length; i <= index; i++) {
mappings[i] = [];
}
return mappings[index];
}
function getColumnIndex(line: SourceMapSegment[], genColumn: number): number {
let index = line.length;
for (let i = index - 1; i >= 0; index = i--) {
const current = line[i];
if (genColumn >= current[COLUMN]) break;
}
return index;
}
function insert<T>(array: T[], index: number, value: T) {
for (let i = array.length; i > index; i--) {
array[i] = array[i - 1];
}
array[index] = value;
}
function removeEmptyFinalLines(mappings: SourceMapSegment[][]) {
const { length } = mappings;
let len = length;
for (let i = len - 1; i >= 0; len = i, i--) {
if (mappings[i].length > 0) break;
}
if (len < length) mappings.length = len;
}
function putAll(strarr: SetArray, array: string[]) {
for (let i = 0; i < array.length; i++) put(strarr, array[i]);
}
function skipSourceless(line: SourceMapSegment[], index: number): boolean {
// The start of a line is already sourceless, so adding a sourceless segment to the beginning
// doesn't generate any useful information.
if (index === 0) return true;
const prev = line[index - 1];
// If the previous segment is also sourceless, then adding another sourceless segment doesn't
// genrate any new information. Else, this segment will end the source/named segment and point to
// a sourceless position, which is useful.
return prev.length === 1;
}
function skipSource(
line: SourceMapSegment[],
index: number,
sourcesIndex: number,
sourceLine: number,
sourceColumn: number,
namesIndex: number,
): boolean {
// A source/named segment at the start of a line gives position at that genColumn
if (index === 0) return false;
const prev = line[index - 1];
// If the previous segment is sourceless, then we're transitioning to a source.
if (prev.length === 1) return false;
// If the previous segment maps to the exact same source position, then this segment doesn't
// provide any new position information.
return (
sourcesIndex === prev[SOURCES_INDEX] &&
sourceLine === prev[SOURCE_LINE] &&
sourceColumn === prev[SOURCE_COLUMN] &&
namesIndex === (prev.length === 5 ? prev[NAMES_INDEX] : NO_NAME)
);
}
function addMappingInternal<S extends string | null | undefined>(
skipable: boolean,
map: GenMapping,
mapping: {
generated: Pos;
source: S;
original: S extends string ? Pos : null | undefined;
name: S extends string ? string | null | undefined : null | undefined;
content: S extends string ? string | null | undefined : null | undefined;
},
) {
const { generated, source, original, name, content } = mapping;
if (!source) {
return addSegmentInternal(
skipable,
map,
generated.line - 1,
generated.column,
null,
null,
null,
null,
null,
);
}
const s: string = source;
assert<Pos>(original);
return addSegmentInternal(
skipable,
map,
generated.line - 1,
generated.column,
s,
original.line - 1,
original.column,
name,
content,
);
}
type GeneratedColumn = number;
type SourcesIndex = number;
type SourceLine = number;
type SourceColumn = number;
type NamesIndex = number;
export type SourceMapSegment =
| [GeneratedColumn]
| [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn]
| [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn, NamesIndex];
export const COLUMN = 0;
export const SOURCES_INDEX = 1;
export const SOURCE_LINE = 2;
export const SOURCE_COLUMN = 3;
export const NAMES_INDEX = 4;
import type { SourceMapSegment } from './sourcemap-segment';
export interface SourceMapV3 {
file?: string | null;
names: readonly string[];
sourceRoot?: string;
sources: readonly (string | null)[];
sourcesContent?: readonly (string | null)[];
version: 3;
}
export interface EncodedSourceMap extends SourceMapV3 {
mappings: string;
}
export interface DecodedSourceMap extends SourceMapV3 {
mappings: readonly SourceMapSegment[][];
}
export interface Pos {
line: number;
column: number;
}
export type Mapping =
| {
generated: Pos;
source: undefined;
original: undefined;
name: undefined;
}
| {
generated: Pos;
source: string;
original: Pos;
name: string;
}
| {
generated: Pos;
source: string;
original: Pos;
name: undefined;
};
{
"name": "@babel/generator",
"version": "7.18.7",
"description": "Turns an AST into code.",
"author": "The Babel Team (https://babel.dev/team)",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/babel/babel.git",
"directory": "packages/babel-generator"
},
"homepage": "https://babel.dev/docs/en/next/babel-generator",
"bugs": "https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20generator%22+is%3Aopen",
"main": "./lib/index.js",
"files": [
"lib"
],
"dependencies": {
"@babel/types": "^7.18.7",
"@jridgewell/gen-mapping": "^0.3.2",
"jsesc": "^2.5.1"
},
"devDependencies": {
"@babel/helper-fixtures": "^7.18.6",
"@babel/parser": "^7.18.6",
"@jridgewell/trace-mapping": "^0.3.8",
"@types/jsesc": "^2.5.0",
"charcodes": "^0.2.0"
},
"engines": {
"node": ">=6.9.0"
},
"type": "commonjs"
}
\ No newline at end of file
MIT License
Copyright (c) 2014-present Sebastian McKenzie and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# @babel/helper-annotate-as-pure
> Helper function to annotate paths and nodes with #__PURE__ comment
See our website [@babel/helper-annotate-as-pure](https://babeljs.io/docs/en/babel-helper-annotate-as-pure) for more information.
## Install
Using npm:
```sh
npm install --save @babel/helper-annotate-as-pure
```
or using yarn:
```sh
yarn add @babel/helper-annotate-as-pure
```
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = annotateAsPure;
var _t = require("@babel/types");
const {
addComment
} = _t;
const PURE_ANNOTATION = "#__PURE__";
const isPureAnnotated = ({
leadingComments
}) => !!leadingComments && leadingComments.some(comment => /[@#]__PURE__/.test(comment.value));
function annotateAsPure(pathOrNode) {
const node = pathOrNode["node"] || pathOrNode;
if (isPureAnnotated(node)) {
return;
}
addComment(node, "leading", PURE_ANNOTATION);
}
\ No newline at end of file
{
"name": "@babel/helper-annotate-as-pure",
"version": "7.18.6",
"description": "Helper function to annotate paths and nodes with #__PURE__ comment",
"repository": {
"type": "git",
"url": "https://github.com/babel/babel.git",
"directory": "packages/babel-helper-annotate-as-pure"
},
"homepage": "https://babel.dev/docs/en/next/babel-helper-annotate-as-pure",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"main": "./lib/index.js",
"dependencies": {
"@babel/types": "^7.18.6"
},
"engines": {
"node": ">=6.9.0"
},
"author": "The Babel Team (https://babel.dev/team)",
"type": "commonjs"
}
\ No newline at end of file
MIT License
Copyright (c) 2014-present Sebastian McKenzie and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# @babel/helper-builder-binary-assignment-operator-visitor
> Helper function to build binary assignment operator visitors
See our website [@babel/helper-builder-binary-assignment-operator-visitor](https://babeljs.io/docs/en/babel-helper-builder-binary-assignment-operator-visitor) for more information.
## Install
Using npm:
```sh
npm install --save @babel/helper-builder-binary-assignment-operator-visitor
```
or using yarn:
```sh
yarn add @babel/helper-builder-binary-assignment-operator-visitor
```
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
var _helperExplodeAssignableExpression = require("@babel/helper-explode-assignable-expression");
var _t = require("@babel/types");
const {
assignmentExpression,
sequenceExpression
} = _t;
function _default(opts) {
const {
build,
operator
} = opts;
const visitor = {
AssignmentExpression(path) {
const {
node,
scope
} = path;
if (node.operator !== operator + "=") return;
const nodes = [];
const exploded = (0, _helperExplodeAssignableExpression.default)(node.left, nodes, this, scope);
nodes.push(assignmentExpression("=", exploded.ref, build(exploded.uid, node.right)));
path.replaceWith(sequenceExpression(nodes));
},
BinaryExpression(path) {
const {
node
} = path;
if (node.operator === operator) {
path.replaceWith(build(node.left, node.right));
}
}
};
return visitor;
}
\ No newline at end of file
{
"name": "@babel/helper-builder-binary-assignment-operator-visitor",
"version": "7.18.6",
"description": "Helper function to build binary assignment operator visitors",
"repository": {
"type": "git",
"url": "https://github.com/babel/babel.git",
"directory": "packages/babel-helper-builder-binary-assignment-operator-visitor"
},
"homepage": "https://babel.dev/docs/en/next/babel-helper-builder-binary-assignment-operator-visitor",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"main": "./lib/index.js",
"dependencies": {
"@babel/helper-explode-assignable-expression": "^7.18.6",
"@babel/types": "^7.18.6"
},
"engines": {
"node": ">=6.9.0"
},
"author": "The Babel Team (https://babel.dev/team)",
"type": "commonjs"
}
\ No newline at end of file
MIT License
Copyright (c) 2014-present Sebastian McKenzie and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# @babel/helper-compilation-targets
> Helper functions on Babel compilation targets
See our website [@babel/helper-compilation-targets](https://babeljs.io/docs/en/babel-helper-compilation-targets) for more information.
## Install
Using npm:
```sh
npm install --save @babel/helper-compilation-targets
```
or using yarn:
```sh
yarn add @babel/helper-compilation-targets
```
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getInclusionReasons = getInclusionReasons;
var _semver = require("semver");
var _pretty = require("./pretty");
var _utils = require("./utils");
function getInclusionReasons(item, targetVersions, list) {
const minVersions = list[item] || {};
return Object.keys(targetVersions).reduce((result, env) => {
const minVersion = (0, _utils.getLowestImplementedVersion)(minVersions, env);
const targetVersion = targetVersions[env];
if (!minVersion) {
result[env] = (0, _pretty.prettifyVersion)(targetVersion);
} else {
const minIsUnreleased = (0, _utils.isUnreleasedVersion)(minVersion, env);
const targetIsUnreleased = (0, _utils.isUnreleasedVersion)(targetVersion, env);
if (!targetIsUnreleased && (minIsUnreleased || _semver.lt(targetVersion.toString(), (0, _utils.semverify)(minVersion)))) {
result[env] = (0, _pretty.prettifyVersion)(targetVersion);
}
}
return result;
}, {});
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = filterItems;
exports.isRequired = isRequired;
exports.targetsSupported = targetsSupported;
var _semver = require("semver");
var _plugins = require("@babel/compat-data/plugins");
var _utils = require("./utils");
function targetsSupported(target, support) {
const targetEnvironments = Object.keys(target);
if (targetEnvironments.length === 0) {
return false;
}
const unsupportedEnvironments = targetEnvironments.filter(environment => {
const lowestImplementedVersion = (0, _utils.getLowestImplementedVersion)(support, environment);
if (!lowestImplementedVersion) {
return true;
}
const lowestTargetedVersion = target[environment];
if ((0, _utils.isUnreleasedVersion)(lowestTargetedVersion, environment)) {
return false;
}
if ((0, _utils.isUnreleasedVersion)(lowestImplementedVersion, environment)) {
return true;
}
if (!_semver.valid(lowestTargetedVersion.toString())) {
throw new Error(`Invalid version passed for target "${environment}": "${lowestTargetedVersion}". ` + "Versions must be in semver format (major.minor.patch)");
}
return _semver.gt((0, _utils.semverify)(lowestImplementedVersion), lowestTargetedVersion.toString());
});
return unsupportedEnvironments.length === 0;
}
function isRequired(name, targets, {
compatData = _plugins,
includes,
excludes
} = {}) {
if (excludes != null && excludes.has(name)) return false;
if (includes != null && includes.has(name)) return true;
return !targetsSupported(targets, compatData[name]);
}
function filterItems(list, includes, excludes, targets, defaultIncludes, defaultExcludes, pluginSyntaxMap) {
const result = new Set();
const options = {
compatData: list,
includes,
excludes
};
for (const item in list) {
if (isRequired(item, targets, options)) {
result.add(item);
} else if (pluginSyntaxMap) {
const shippedProposalsSyntax = pluginSyntaxMap.get(item);
if (shippedProposalsSyntax) {
result.add(shippedProposalsSyntax);
}
}
}
if (defaultIncludes) {
defaultIncludes.forEach(item => !excludes.has(item) && result.add(item));
}
if (defaultExcludes) {
defaultExcludes.forEach(item => !includes.has(item) && result.delete(item));
}
return result;
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "TargetNames", {
enumerable: true,
get: function () {
return _options.TargetNames;
}
});
exports.default = getTargets;
Object.defineProperty(exports, "filterItems", {
enumerable: true,
get: function () {
return _filterItems.default;
}
});
Object.defineProperty(exports, "getInclusionReasons", {
enumerable: true,
get: function () {
return _debug.getInclusionReasons;
}
});
exports.isBrowsersQueryValid = isBrowsersQueryValid;
Object.defineProperty(exports, "isRequired", {
enumerable: true,
get: function () {
return _filterItems.isRequired;
}
});
Object.defineProperty(exports, "prettifyTargets", {
enumerable: true,
get: function () {
return _pretty.prettifyTargets;
}
});
Object.defineProperty(exports, "unreleasedLabels", {
enumerable: true,
get: function () {
return _targets.unreleasedLabels;
}
});
var _browserslist = require("browserslist");
var _helperValidatorOption = require("@babel/helper-validator-option");
var _nativeModules = require("@babel/compat-data/native-modules");
var _utils = require("./utils");
var _targets = require("./targets");
var _options = require("./options");
var _pretty = require("./pretty");
var _debug = require("./debug");
var _filterItems = require("./filter-items");
const ESM_SUPPORT = _nativeModules["es6.module"];
const v = new _helperValidatorOption.OptionValidator("@babel/helper-compilation-targets");
function validateTargetNames(targets) {
const validTargets = Object.keys(_options.TargetNames);
for (const target of Object.keys(targets)) {
if (!(target in _options.TargetNames)) {
throw new Error(v.formatMessage(`'${target}' is not a valid target
- Did you mean '${(0, _helperValidatorOption.findSuggestion)(target, validTargets)}'?`));
}
}
return targets;
}
function isBrowsersQueryValid(browsers) {
return typeof browsers === "string" || Array.isArray(browsers) && browsers.every(b => typeof b === "string");
}
function validateBrowsers(browsers) {
v.invariant(browsers === undefined || isBrowsersQueryValid(browsers), `'${String(browsers)}' is not a valid browserslist query`);
return browsers;
}
function getLowestVersions(browsers) {
return browsers.reduce((all, browser) => {
const [browserName, browserVersion] = browser.split(" ");
const target = _targets.browserNameMap[browserName];
if (!target) {
return all;
}
try {
const splitVersion = browserVersion.split("-")[0].toLowerCase();
const isSplitUnreleased = (0, _utils.isUnreleasedVersion)(splitVersion, target);
if (!all[target]) {
all[target] = isSplitUnreleased ? splitVersion : (0, _utils.semverify)(splitVersion);
return all;
}
const version = all[target];
const isUnreleased = (0, _utils.isUnreleasedVersion)(version, target);
if (isUnreleased && isSplitUnreleased) {
all[target] = (0, _utils.getLowestUnreleased)(version, splitVersion, target);
} else if (isUnreleased) {
all[target] = (0, _utils.semverify)(splitVersion);
} else if (!isUnreleased && !isSplitUnreleased) {
const parsedBrowserVersion = (0, _utils.semverify)(splitVersion);
all[target] = (0, _utils.semverMin)(version, parsedBrowserVersion);
}
} catch (e) {}
return all;
}, {});
}
function outputDecimalWarning(decimalTargets) {
if (!decimalTargets.length) {
return;
}
console.warn("Warning, the following targets are using a decimal version:\n");
decimalTargets.forEach(({
target,
value
}) => console.warn(` ${target}: ${value}`));
console.warn(`
We recommend using a string for minor/patch versions to avoid numbers like 6.10
getting parsed as 6.1, which can lead to unexpected behavior.
`);
}
function semverifyTarget(target, value) {
try {
return (0, _utils.semverify)(value);
} catch (error) {
throw new Error(v.formatMessage(`'${value}' is not a valid value for 'targets.${target}'.`));
}
}
function nodeTargetParser(value) {
const parsed = value === true || value === "current" ? process.versions.node : semverifyTarget("node", value);
return ["node", parsed];
}
function defaultTargetParser(target, value) {
const version = (0, _utils.isUnreleasedVersion)(value, target) ? value.toLowerCase() : semverifyTarget(target, value);
return [target, version];
}
function generateTargets(inputTargets) {
const input = Object.assign({}, inputTargets);
delete input.esmodules;
delete input.browsers;
return input;
}
function resolveTargets(queries, env) {
const resolved = _browserslist(queries, {
mobileToDesktop: true,
env
});
return getLowestVersions(resolved);
}
function getTargets(inputTargets = {}, options = {}) {
var _browsers, _browsers2;
let {
browsers,
esmodules
} = inputTargets;
const {
configPath = "."
} = options;
validateBrowsers(browsers);
const input = generateTargets(inputTargets);
let targets = validateTargetNames(input);
const shouldParseBrowsers = !!browsers;
const hasTargets = shouldParseBrowsers || Object.keys(targets).length > 0;
const shouldSearchForConfig = !options.ignoreBrowserslistConfig && !hasTargets;
if (!browsers && shouldSearchForConfig) {
browsers = _browserslist.loadConfig({
config: options.configFile,
path: configPath,
env: options.browserslistEnv
});
if (browsers == null) {
{
browsers = [];
}
}
}
if (esmodules && (esmodules !== "intersect" || !((_browsers = browsers) != null && _browsers.length))) {
browsers = Object.keys(ESM_SUPPORT).map(browser => `${browser} >= ${ESM_SUPPORT[browser]}`).join(", ");
esmodules = false;
}
if ((_browsers2 = browsers) != null && _browsers2.length) {
const queryBrowsers = resolveTargets(browsers, options.browserslistEnv);
if (esmodules === "intersect") {
for (const browser of Object.keys(queryBrowsers)) {
const version = queryBrowsers[browser];
const esmSupportVersion = ESM_SUPPORT[browser];
if (esmSupportVersion) {
queryBrowsers[browser] = (0, _utils.getHighestUnreleased)(version, (0, _utils.semverify)(esmSupportVersion), browser);
} else {
delete queryBrowsers[browser];
}
}
}
targets = Object.assign(queryBrowsers, targets);
}
const result = {};
const decimalWarnings = [];
for (const target of Object.keys(targets).sort()) {
const value = targets[target];
if (typeof value === "number" && value % 1 !== 0) {
decimalWarnings.push({
target,
value
});
}
const [parsedTarget, parsedValue] = target === "node" ? nodeTargetParser(value) : defaultTargetParser(target, value);
if (parsedValue) {
result[parsedTarget] = parsedValue;
}
}
outputDecimalWarning(decimalWarnings);
return result;
}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.TargetNames = void 0;
const TargetNames = {
node: "node",
chrome: "chrome",
opera: "opera",
edge: "edge",
firefox: "firefox",
safari: "safari",
ie: "ie",
ios: "ios",
android: "android",
electron: "electron",
samsung: "samsung",
rhino: "rhino"
};
exports.TargetNames = TargetNames;
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.prettifyTargets = prettifyTargets;
exports.prettifyVersion = prettifyVersion;
var _semver = require("semver");
var _targets = require("./targets");
function prettifyVersion(version) {
if (typeof version !== "string") {
return version;
}
const parts = [_semver.major(version)];
const minor = _semver.minor(version);
const patch = _semver.patch(version);
if (minor || patch) {
parts.push(minor);
}
if (patch) {
parts.push(patch);
}
return parts.join(".");
}
function prettifyTargets(targets) {
return Object.keys(targets).reduce((results, target) => {
let value = targets[target];
const unreleasedLabel = _targets.unreleasedLabels[target];
if (typeof value === "string" && unreleasedLabel !== value) {
value = prettifyVersion(value);
}
results[target] = value;
return results;
}, {});
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment