Repository: karen-irc/option-t
Pull request #1034 (2021-06-06 12:50:20)

Remove unused `QuirksLegacyExposedPath.hasExtension()`


Patch:
diff --git a/tools/generate_import_path_list_markdown.mjs b/tools/generate_import_path_list_markdown.mjs
index 1e7df013..4a64720d 100644
--- a/tools/generate_import_path_list_markdown.mjs
+++ b/tools/generate_import_path_list_markdown.mjs
@@ -127,7 +127,7 @@ ${str}
     const list = Array.from(apiList)
         .map((pathItem) => {
             const key = pathItem.name();
-            const path = pathItem.path();
+            const path = pathItem.filepath();
             const item = new ListItem(key, path);
             return item;
         });
diff --git a/tools/package_json_rewriter/transformer/add_exports_field/ExportEntry.mjs b/tools/package_json_rewriter/transformer/add_exports_field/ExportEntry.mjs
index ba545081..9a081491 100644
--- a/tools/package_json_rewriter/transformer/add_exports_field/ExportEntry.mjs
+++ b/tools/package_json_rewriter/transformer/add_exports_field/ExportEntry.mjs
@@ -62,18 +62,7 @@ export class CompatExportEntry extends AbstractExportEntry {
         return k;
     }
 
-    path() {
-        const original = this._original;
-        const hasExtension = original.hasExtension();
-        if (!hasExtension) {
-            return this._pathForNoExtension();
-        }
-
-        const p = this.key();
-        return p;
-    }
-
-    _pathForNoExtension() {
+    filepath() {
         const original = this._original;
         const key = this.key();
         if (original.isESM()) {
diff --git a/tools/package_json_rewriter/transformer/add_exports_field/compatibility.mjs b/tools/package_json_rewriter/transformer/add_exports_field/compatibility.mjs
index 80c1a281..e58779b2 100644
--- a/tools/package_json_rewriter/transformer/add_exports_field/compatibility.mjs
+++ b/tools/package_json_rewriter/transformer/add_exports_field/compatibility.mjs
@@ -16,7 +16,7 @@ export function addHistoricalPathToExportsFields(o, histricalJSPathSeq) {
 
         const entry = new CompatExportEntry(original);
         const key = entry.key();
-        const filepath = entry.path();
+        const filepath = entry.filepath();
         // eslint-disable-next-line no-param-reassign
         o[key] = filepath;
     }
diff --git a/tools/package_json_rewriter/transformer/add_exports_field/public_api.mjs b/tools/package_json_rewriter/transformer/add_exports_field/public_api.mjs
index 0b96e9f1..c36a65cb 100644
--- a/tools/package_json_rewriter/transformer/add_exports_field/public_api.mjs
+++ b/tools/package_json_rewriter/transformer/add_exports_field/public_api.mjs
@@ -8,7 +8,7 @@ export function loadPublicAPIDefinitions(seq) {
         assert.ok(!item.isForCompat());
 
         const name = item.name();
-        const path = item.path();
+        const path = item.filepath();
         const entry = new ExportEntry(name, path);
         EXPORT_ENTRIES.push(entry);
     }
diff --git a/tools/public_api/ExposedPath.mjs b/tools/public_api/ExposedPath.mjs
index 176d7e27..1b8b3654 100644
--- a/tools/public_api/ExposedPath.mjs
+++ b/tools/public_api/ExposedPath.mjs
@@ -13,7 +13,7 @@ export class ExposedPath {
         return this._key;
     }
 
-    path() {
+    filepath() {
         return this._raw.path ?? null;
     }
 
@@ -43,13 +43,13 @@ export class QuirksLegacyExposedPath extends ExposedPath {
 
     isESM() {
         const name = this.name();
-        const isESM = /^esm\//u.test(name) || /\.mjs$/u.test(name);
+        const isESM = /^esm\//u.test(name);
         return isESM;
     }
 
     isCJS() {
         const name = this.name();
-        const isCJS = /^cjs\//u.test(name) || /\.js$/u.test(name);
+        const isCJS = /^cjs\//u.test(name);
         return isCJS;
     }
 
@@ -58,16 +58,6 @@ export class QuirksLegacyExposedPath extends ExposedPath {
         const ok = /^lib\//u.test(name);
         return ok;
     }
-
-    isLibButWithoutExtension() {
-        return this.isLib() && !this.hasExtension();
-    }
-
-    hasExtension() {
-        const name = this.name();
-        const has = /\.(js|mjs|cjs)$/u.test(name);
-        return has;
-    }
 }
 
 export function* generateExposedPathSequence() {


Test patch:
diff --git a/tools/test_package_exports.mjs b/tools/test_package_exports.mjs
index 7270a204..10f5b855 100644
--- a/tools/test_package_exports.mjs
+++ b/tools/test_package_exports.mjs
@@ -56,7 +56,7 @@ async function tryImportPathForCompat(pathItem) {
     else if (pathItem.isCJS()) {
         tryImportPathAsCJS(pathItem);
     }
-    else if (pathItem.isLibButWithoutExtension()) {
+    else if (pathItem.isLib()) {
         tryImportPathAsCJS(pathItem);
         await tryImportPathAsESM(pathItem);
     }