@formspec/build 0.1.0-alpha.52 → 0.1.0-alpha.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/internals.js CHANGED
@@ -1010,39 +1010,85 @@ function isNonReferenceIdentifier(node) {
1010
1010
  }
1011
1011
  return false;
1012
1012
  }
1013
- function statementReferencesImportedName(statement, importedNames) {
1013
+ function astReferencesImportedName(root, importedNames) {
1014
1014
  if (importedNames.size === 0) {
1015
1015
  return false;
1016
1016
  }
1017
- let referencesImportedName = false;
1017
+ let found = false;
1018
1018
  const visit = (node) => {
1019
- if (referencesImportedName) {
1020
- return;
1021
- }
1019
+ if (found) return;
1022
1020
  if (ts4.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
1023
- referencesImportedName = true;
1021
+ found = true;
1024
1022
  return;
1025
1023
  }
1026
1024
  ts4.forEachChild(node, visit);
1027
1025
  };
1028
- visit(statement);
1029
- return referencesImportedName;
1026
+ visit(root);
1027
+ return found;
1028
+ }
1029
+ function getObjectMembers(statement) {
1030
+ if (ts4.isInterfaceDeclaration(statement)) {
1031
+ return statement.members;
1032
+ }
1033
+ if (ts4.isTypeLiteralNode(statement.type)) {
1034
+ return statement.type.members;
1035
+ }
1036
+ return void 0;
1037
+ }
1038
+ function rewriteImportedMemberTypes(statement, sourceFile, importedNames) {
1039
+ const members = getObjectMembers(statement);
1040
+ if (members === void 0) {
1041
+ return null;
1042
+ }
1043
+ const replacements = [];
1044
+ for (const member of members) {
1045
+ if (!ts4.isPropertySignature(member)) {
1046
+ if (astReferencesImportedName(member, importedNames)) {
1047
+ return null;
1048
+ }
1049
+ continue;
1050
+ }
1051
+ const typeAnnotation = member.type;
1052
+ if (typeAnnotation === void 0) continue;
1053
+ if (astReferencesImportedName(typeAnnotation, importedNames)) {
1054
+ replacements.push({
1055
+ start: typeAnnotation.getStart(sourceFile),
1056
+ end: typeAnnotation.getEnd()
1057
+ });
1058
+ }
1059
+ }
1060
+ if (replacements.length === 0) {
1061
+ return statement.getText(sourceFile);
1062
+ }
1063
+ const stmtStart = statement.getStart(sourceFile);
1064
+ let result = statement.getText(sourceFile);
1065
+ for (const { start, end } of [...replacements].reverse()) {
1066
+ result = result.slice(0, start - stmtStart) + "unknown" + result.slice(end - stmtStart);
1067
+ }
1068
+ return result;
1030
1069
  }
1031
1070
  function buildSupportingDeclarations(sourceFile, extensionTypeNames) {
1032
1071
  const importedNames = collectImportedNames(sourceFile);
1033
1072
  const importedNamesToSkip = new Set(
1034
1073
  [...importedNames].filter((name) => !extensionTypeNames.has(name))
1035
1074
  );
1036
- return sourceFile.statements.filter((statement) => {
1037
- if (ts4.isImportDeclaration(statement)) return false;
1038
- if (ts4.isImportEqualsDeclaration(statement)) return false;
1039
- if (ts4.isExportDeclaration(statement) && statement.moduleSpecifier !== void 0)
1040
- return false;
1041
- if (statementReferencesImportedName(statement, importedNamesToSkip)) {
1042
- return false;
1075
+ const result = [];
1076
+ for (const statement of sourceFile.statements) {
1077
+ if (ts4.isImportDeclaration(statement)) continue;
1078
+ if (ts4.isImportEqualsDeclaration(statement)) continue;
1079
+ if (ts4.isExportDeclaration(statement) && statement.moduleSpecifier !== void 0) continue;
1080
+ if (!astReferencesImportedName(statement, importedNamesToSkip)) {
1081
+ result.push(statement.getText(sourceFile));
1082
+ continue;
1043
1083
  }
1044
- return true;
1045
- }).map((statement) => statement.getText(sourceFile));
1084
+ if (ts4.isInterfaceDeclaration(statement) || ts4.isTypeAliasDeclaration(statement)) {
1085
+ const rewritten = rewriteImportedMemberTypes(statement, sourceFile, importedNamesToSkip);
1086
+ if (rewritten !== null) {
1087
+ result.push(rewritten);
1088
+ }
1089
+ }
1090
+ }
1091
+ return result;
1046
1092
  }
1047
1093
  function pushUniqueCompilerDiagnostics(target, additions) {
1048
1094
  for (const diagnostic of additions) {