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
+72
View File
@@ -0,0 +1,72 @@
"use strict";
exports.__esModule = true;
exports.default = void 0;
var _skip = require("./skip");
var _parseNamedImports = _interopRequireDefault(require("./parse-named-imports"));
var _parseNamespaceImport = _interopRequireDefault(require("./parse-namespace-import"));
var _parseDefaultImport = _interopRequireDefault(require("./parse-default-import"));
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.
*/
// Assumes import clause is syntactically valid
const parseImportClause = importClauseString => {
let defaultImport;
let namespaceImport;
const namedImports = [];
for (let i = 0; i < importClauseString.length; i++) {
if (_skip.separatorRegex.test(importClauseString[i])) {
continue;
}
if (importClauseString[i] === `{`) {
let newNamedImports;
({
namedImports: newNamedImports,
i
} = (0, _parseNamedImports.default)(importClauseString, i));
namedImports.push(...newNamedImports);
} else if (importClauseString[i] === `*`) {
;
({
namespaceImport,
i
} = (0, _parseNamespaceImport.default)(importClauseString, i));
} else {
;
({
defaultImport,
i
} = (0, _parseDefaultImport.default)(importClauseString, i));
}
}
return {
default: defaultImport,
namespace: namespaceImport,
named: namedImports
};
};
var _default = parseImportClause;
exports.default = _default;
@@ -0,0 +1,33 @@
"use strict";
exports.__esModule = true;
exports.default = void 0;
var _skip = require("./skip");
/**
* 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 parseDefaultImport = (importClauseString, i) => {
const startIndex = i;
i = (0, _skip.skipNonSeparators)(importClauseString, i);
return {
defaultImport: importClauseString.substring(startIndex, i),
i
};
};
var _default = parseDefaultImport;
exports.default = _default;
@@ -0,0 +1,53 @@
"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.
*/
const parseNamedImports = (importClauseString, i) => {
const startIndex = ++i;
while (i < importClauseString.length && importClauseString[i] !== `}`) {
i++;
}
const namedImports = importClauseString.substring(startIndex, i++).split(`,`).map(namedImport => {
namedImport = namedImport.trim();
if (namedImport.includes(` `)) {
const components = namedImport.split(` `);
return {
specifier: components[0],
binding: components[components.length - 1]
};
}
return {
specifier: namedImport,
binding: namedImport
};
}).filter(({
specifier
}) => specifier.length > 0);
return {
namedImports,
i
};
};
var _default = parseNamedImports;
exports.default = _default;
@@ -0,0 +1,37 @@
"use strict";
exports.__esModule = true;
exports.default = void 0;
var _skip = require("./skip");
/**
* 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 parseNamespaceImport = (importClauseString, i) => {
i++;
i = (0, _skip.skipSeparators)(importClauseString, i);
i += `as`.length;
i = (0, _skip.skipSeparators)(importClauseString, i);
const startIndex = i;
i = (0, _skip.skipNonSeparators)(importClauseString, i);
return {
namespaceImport: importClauseString.substring(startIndex, i),
i
};
};
var _default = parseNamespaceImport;
exports.default = _default;
+42
View File
@@ -0,0 +1,42 @@
"use strict";
exports.__esModule = true;
exports.skipNonSeparators = exports.skipSeparators = exports.separatorRegex = 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.
*/
const separatorRegex = /^(?:\s+|,)$/u;
exports.separatorRegex = separatorRegex;
const skipSeparators = (imported, i) => {
while (i < imported.length && separatorRegex.test(imported[i])) {
i++;
}
return i;
};
exports.skipSeparators = skipSeparators;
const skipNonSeparators = (imported, i) => {
while (i < imported.length && !separatorRegex.test(imported[i])) {
i++;
}
return i;
};
exports.skipNonSeparators = skipNonSeparators;