This commit is contained in:
Tutur33
2023-11-24 22:35:41 +01:00
parent 3c0b507a93
commit 7644b2a0f7
45165 changed files with 4803356 additions and 3 deletions
+55
View File
@@ -0,0 +1,55 @@
"use strict";
exports.__esModule = true;
exports.default = void 0;
var _slashes = require("slashes");
var _isConstantStringLiteral = _interopRequireDefault(require("./is-constant-string-literal"));
var _parseType = _interopRequireDefault(require("./parse-type"));
var _resolve = _interopRequireDefault(require("./resolve"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const parseModuleSpecifier = (moduleSpecifierString, {
isDynamicImport,
resolveFrom
}) => {
const {
isConstant,
value
} = !isDynamicImport || (0, _isConstantStringLiteral.default)(moduleSpecifierString) ? {
isConstant: true,
value: (0, _slashes.stripSlashes)(moduleSpecifierString.substring(1, moduleSpecifierString.length - 1))
} : {
isConstant: false,
value: undefined
};
return {
type: isConstant ? (0, _parseType.default)(value) : `unknown`,
isConstant,
code: moduleSpecifierString,
value,
resolved: typeof resolveFrom === `string` && isConstant ? (0, _resolve.default)(resolveFrom, value) : undefined
};
};
var _default = parseModuleSpecifier;
exports.default = _default;
@@ -0,0 +1,45 @@
"use strict";
exports.__esModule = true;
exports.default = void 0;
/**
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Assumes the string is syntactically valid
const isConstantStringLiteral = stringLiteral => {
const quote = [`'`, `"`, `\``].find(quoteCandidate => stringLiteral.startsWith(quoteCandidate) && stringLiteral.endsWith(quoteCandidate));
if (quote == null) {
return false;
}
for (let i = 1; i < stringLiteral.length - 1; i++) {
// Check for end of string literal before end of stringLiteral
if (stringLiteral[i] === quote && stringLiteral[i - 1] !== `\\`) {
return false;
} // Check for interpolated value in template literal
if (quote === `\`` && stringLiteral.substring(i, i + 2) === `\${` && stringLiteral[i - 1] !== `\\`) {
return false;
}
}
return true;
};
var _default = isConstantStringLiteral;
exports.default = _default;
@@ -0,0 +1,48 @@
"use strict";
exports.__esModule = true;
exports.default = void 0;
var _module2 = _interopRequireDefault(require("module"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const builtinModules = new Set(_module2.default.builtinModules);
const parseType = moduleSpecifier => {
if (moduleSpecifier.length === 0) {
return `invalid`;
}
if (moduleSpecifier.startsWith(`/`)) {
return `absolute`;
}
if (moduleSpecifier.startsWith(`.`)) {
return `relative`;
}
if (builtinModules.has(moduleSpecifier)) {
return `builtin`;
}
return `package`;
};
var _default = parseType;
exports.default = _default;
+34
View File
@@ -0,0 +1,34 @@
"use strict";
exports.__esModule = true;
exports.default = void 0;
var _path = require("path");
/**
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const resolve = (from, to) => {
try {
return require.resolve(to, {
paths: [(0, _path.dirname)(from)]
});
} catch {
return undefined;
}
};
var _default = resolve;
exports.default = _default;