diff --git a/packages/typia/native/cmd/ttsc-typia/build.go b/packages/typia/native/cmd/ttsc-typia/build.go
index be63f724d7..9faf29aff3 100644
--- a/packages/typia/native/cmd/ttsc-typia/build.go
+++ b/packages/typia/native/cmd/ttsc-typia/build.go
@@ -14,6 +14,7 @@ import (
"github.com/samchon/ttsc/packages/ttsc/driver"
typiaadapter "github.com/samchon/typia/packages/typia/native/adapter"
nativecontext "github.com/samchon/typia/packages/typia/native/core/context"
+ schemametadata "github.com/samchon/typia/packages/typia/native/core/schemas/metadata"
nativetransform "github.com/samchon/typia/packages/typia/native/transform"
)
@@ -107,6 +108,8 @@ func runBuild(args []string) int {
}
}
defer prog.Close()
+ registerTypiaDefaultLibraryClassifier(prog)
+ defer schemametadata.MetadataDefaultLibrary_release(prog.Checker)
transformDiags := []typiaTransformDiagnostic{}
transformOptions := pluginOptions.TransformOptions()
diff --git a/packages/typia/native/cmd/ttsc-typia/default_library_spoof_native_identity_transform_test.go b/packages/typia/native/cmd/ttsc-typia/default_library_spoof_native_identity_transform_test.go
new file mode 100644
index 0000000000..7152406689
--- /dev/null
+++ b/packages/typia/native/cmd/ttsc-typia/default_library_spoof_native_identity_transform_test.go
@@ -0,0 +1,216 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "strings"
+ "testing"
+)
+
+// TestDefaultLibrarySpoofNativeIdentityTransform keeps a declaration package out
+// of the runtime-native authority even when its file is named like a TypeScript
+// default library (#2200).
+//
+// Runtime-native identity admits a global whose constructor a default library
+// provides, so how "default library" is decided is the whole boundary. `lib.d.ts`
+// is an ordinary published file name, so a base-name test makes that authority
+// claimable by any package a project pulls in through `typeRoots` — the forged
+// declarations below are a full-member copy of the DOM `File` and `Blob`,
+// including their `declare var` constructor bindings, and nothing but the
+// containing directory distinguishes them from the real thing.
+//
+// 1. Publish `lib.dom.d.ts` and `lib.es5.d.ts` from a fixture `@types` package
+// that declares global File and Blob with their constructors.
+// 2. Transform validators for those globals with no DOM library and no Node
+// types loaded, so the forged package is their only declaration source.
+// 3. Require the emit to keep the forged members instead of an `instanceof`.
+// 4. Execute the validators in Node against the forged structural values and
+// against the real runtime instances, requiring an exact case count.
+func TestDefaultLibrarySpoofNativeIdentityTransform(t *testing.T) {
+ project := defaultLibrarySpoofNativeIdentityProject(t)
+ js, errText, code := ttscTypiaTestCapture(func() int {
+ return runTransform([]string{
+ "--cwd", project,
+ "--tsconfig", "tsconfig.json",
+ "--file", "src/input.ts",
+ "--output", "js",
+ })
+ })
+ if code != 0 {
+ t.Fatalf("default library spoof transform failed: code=%d stderr=\n%s", code, errText)
+ }
+
+ failures := []string{}
+ for _, native := range []string{"instanceof File", "instanceof Blob"} {
+ if strings.Contains(js, native) {
+ failures = append(failures, fmt.Sprintf("a lib.*.d.ts named package declaration was promoted to %q", native))
+ }
+ }
+ for _, member := range []string{"spoofBlobBrand", "spoofFileBrand"} {
+ if !strings.Contains(js, member) {
+ failures = append(failures, fmt.Sprintf("emit dropped forged declaration member %q", member))
+ }
+ }
+
+ output, runtimeErr := defaultLibrarySpoofNativeIdentityRun(t, project, js)
+ if runtimeErr != nil {
+ failures = append(failures, fmt.Sprintf("runtime matrix failed: %v\n%s", runtimeErr, output))
+ }
+ if expected := "RAN 6 SPOOF CASES"; !strings.Contains(output, expected) {
+ failures = append(failures, fmt.Sprintf("spoof runner did not report %q; got:\n%s", expected, output))
+ }
+ if len(failures) != 0 {
+ t.Fatalf("default library spoof mismatches:\n%s\n\nemit:\n%s", strings.Join(failures, "\n"), js)
+ }
+}
+
+func defaultLibrarySpoofNativeIdentityProject(t *testing.T) string {
+ t.Helper()
+ root := ttscTypiaTestRepoRoot(t)
+ base := filepath.Join(root, "packages", "typia", "native", ".tmp-ttsc-typia-tests")
+ if err := os.MkdirAll(base, 0o755); err != nil {
+ t.Fatalf("mkdir temp base: %v", err)
+ }
+ dir, err := os.MkdirTemp(base, "default-library-spoof-native-identity-")
+ if err != nil {
+ t.Fatalf("create temp fixture: %v", err)
+ }
+ t.Cleanup(func() {
+ _ = os.RemoveAll(dir)
+ })
+ for name, content := range map[string]string{
+ "tsconfig.json": defaultLibrarySpoofNativeIdentityTSConfig,
+ "node_modules/@types/spoof-lib/package.json": defaultLibrarySpoofNativeIdentityPackageJSON,
+ "node_modules/@types/spoof-lib/lib.dom.d.ts": defaultLibrarySpoofNativeIdentityDeclarations,
+ "node_modules/@types/spoof-lib/lib.es5.d.ts": defaultLibrarySpoofNativeIdentityExtraDeclarations,
+ "src/input.ts": defaultLibrarySpoofNativeIdentitySource,
+ } {
+ path := filepath.Join(dir, filepath.FromSlash(name))
+ if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
+ t.Fatalf("mkdir fixture path %s: %v", filepath.Dir(path), err)
+ }
+ if err := os.WriteFile(path, []byte(content), 0o644); err != nil {
+ t.Fatalf("write fixture file %s: %v", path, err)
+ }
+ }
+ return dir
+}
+
+func defaultLibrarySpoofNativeIdentityRun(t *testing.T, project string, js string) (string, error) {
+ t.Helper()
+ node, err := exec.LookPath("node")
+ if err != nil {
+ t.Skip("node executable not found")
+ return "", nil
+ }
+ runtimeDir := filepath.Join(project, "runtime")
+ if err := os.MkdirAll(runtimeDir, 0o755); err != nil {
+ t.Fatalf("mkdir runtime dir: %v", err)
+ }
+ ttscTypiaTestWriteCommonRuntimeStubs(t, runtimeDir)
+ for name, content := range map[string]string{
+ "input.cjs": ttscTypiaTestRewriteCommonJS(t, js),
+ "run.cjs": defaultLibrarySpoofNativeIdentityRuntimeRunner,
+ } {
+ if err := os.WriteFile(filepath.Join(runtimeDir, name), []byte(content), 0o644); err != nil {
+ t.Fatalf("write runtime file %s: %v", name, err)
+ }
+ }
+ cmd := exec.Command(node, filepath.Join(runtimeDir, "run.cjs"))
+ cmd.Dir = runtimeDir
+ output, err := cmd.CombinedOutput()
+ return string(output), err
+}
+
+const defaultLibrarySpoofNativeIdentityTSConfig = `{
+ "compilerOptions": {
+ "target": "ES2022",
+ "module": "commonjs",
+ "moduleResolution": "bundler",
+ "ignoreDeprecations": "6.0",
+ "lib": ["ES2022"],
+ "types": ["spoof-lib"],
+ "esModuleInterop": true,
+ "strict": true,
+ "skipLibCheck": true
+ },
+ "include": ["src"]
+}
+`
+
+const defaultLibrarySpoofNativeIdentityPackageJSON = `{
+ "name": "@types/spoof-lib",
+ "version": "1.0.0",
+ "types": "lib.dom.d.ts"
+}
+`
+
+const defaultLibrarySpoofNativeIdentityDeclarations = `///
+
+interface Blob {
+ readonly size: number;
+ readonly type: string;
+ spoofBlobBrand: string;
+}
+declare var Blob: {
+ prototype: Blob;
+ new (parts?: unknown[], options?: unknown): Blob;
+};
+`
+
+const defaultLibrarySpoofNativeIdentityExtraDeclarations = `interface File extends Blob {
+ readonly lastModified: number;
+ readonly name: string;
+ readonly webkitRelativePath: string;
+ spoofFileBrand: string;
+}
+declare var File: {
+ prototype: File;
+ new (parts: unknown[], name: string, options?: unknown): File;
+};
+`
+
+const defaultLibrarySpoofNativeIdentitySource = `import typia from "typia";
+
+export const createdIsBlob = typia.createIs();
+export const createdIsFile = typia.createIs();
+`
+
+const defaultLibrarySpoofNativeIdentityRuntimeRunner = `const validators = require("./input.cjs");
+
+let ran = 0;
+const failures = [];
+const eq = (name, actual, expected) => {
+ ran += 1;
+ if (actual !== expected) {
+ failures.push(name + ": expected " + expected + " but got " + actual);
+ }
+};
+
+const spoofBlob = {
+ size: 1,
+ type: "text/plain",
+ spoofBlobBrand: "spoof",
+};
+const spoofFile = {
+ ...spoofBlob,
+ lastModified: 0,
+ name: "x.txt",
+ webkitRelativePath: "",
+ spoofFileBrand: "spoof",
+};
+
+eq("spoof Blob structural", validators.createdIsBlob(spoofBlob), true);
+eq("spoof Blob rejects runtime instance", validators.createdIsBlob(new Blob(["x"])), false);
+eq("spoof Blob missing brand", validators.createdIsBlob({ size: 1, type: "text/plain" }), false);
+eq("spoof File structural", validators.createdIsFile(spoofFile), true);
+eq("spoof File rejects runtime instance", validators.createdIsFile(new File(["x"], "x.txt")), false);
+eq("spoof File missing brand", validators.createdIsFile({ ...spoofFile, spoofFileBrand: undefined }), false);
+
+console.log("RAN " + ran + " SPOOF CASES");
+if (failures.length !== 0) {
+ throw new Error("MISMATCHES:\n" + failures.join("\n"));
+}
+`
diff --git a/packages/typia/native/cmd/ttsc-typia/lib_replacement_native_identity_transform_test.go b/packages/typia/native/cmd/ttsc-typia/lib_replacement_native_identity_transform_test.go
new file mode 100644
index 0000000000..a3ae69663c
--- /dev/null
+++ b/packages/typia/native/cmd/ttsc-typia/lib_replacement_native_identity_transform_test.go
@@ -0,0 +1,277 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "strings"
+ "testing"
+)
+
+// TestLibReplacementNativeIdentityTransform keeps a `libReplacement` project's
+// natives native even though their declaration file lives in node_modules
+// (#2200).
+//
+// Runtime-native identity requires a runtime authority to declare the global, so
+// which files count as a TypeScript default library became load-bearing. Under
+// `libReplacement` the compiler resolves `lib.es2015.collection.d.ts` to
+// `@typescript/lib-es2015/collection`, an ordinary package file whose name does
+// not even begin with `lib.` — so a file-name rule answers "not a default
+// library" and would demote Map, Set, WeakMap, and WeakSet to structural checks
+// that accept any object. Only the program's own classification is right here,
+// and this fixture is what proves the transform consults it.
+//
+// 1. Publish `@typescript/lib-es2015/collection.d.ts` carrying the real
+// Map/Set/WeakMap/WeakSet declarations plus a probe interface that exists
+// nowhere else, and enable `libReplacement`.
+// 2. Transform validators for the four replaced collection natives, for Date
+// and Uint8Array as bundled-library controls, and for the probe.
+// 3. Require the probe to transform at all, which fails unless the replacement
+// file — not the bundled lib — is what the program loaded.
+// 4. Require every native to keep its `instanceof` check and execute all of
+// them in Node against real instances and plain objects.
+func TestLibReplacementNativeIdentityTransform(t *testing.T) {
+ project := libReplacementNativeIdentityProject(t)
+ js, errText, code := ttscTypiaTestCapture(func() int {
+ return runTransform([]string{
+ "--cwd", project,
+ "--tsconfig", "tsconfig.json",
+ "--file", "src/input.ts",
+ "--output", "js",
+ })
+ })
+ if code != 0 {
+ t.Fatalf("lib replacement transform failed: code=%d stderr=\n%s", code, errText)
+ }
+
+ failures := []string{}
+ if !strings.Contains(js, "libReplacementMarker") {
+ failures = append(failures, "emit lost the replacement-only probe member; the project did not load the replaced lib file")
+ }
+ for _, kept := range []string{
+ "instanceof Map",
+ "instanceof Set",
+ "instanceof WeakMap",
+ "instanceof WeakSet",
+ "instanceof Date",
+ "instanceof Uint8Array",
+ } {
+ if !strings.Contains(js, kept) {
+ failures = append(failures, fmt.Sprintf("replaced or bundled default library native lost %q", kept))
+ }
+ }
+
+ output, runtimeErr := libReplacementNativeIdentityRun(t, project, js)
+ if runtimeErr != nil {
+ failures = append(failures, fmt.Sprintf("runtime matrix failed: %v\n%s", runtimeErr, output))
+ }
+ if expected := "RAN 13 REPLACEMENT CASES"; !strings.Contains(output, expected) {
+ failures = append(failures, fmt.Sprintf("replacement runner did not report %q; got:\n%s", expected, output))
+ }
+ if len(failures) != 0 {
+ t.Fatalf("lib replacement native identity mismatches:\n%s\n\nemit:\n%s", strings.Join(failures, "\n"), js)
+ }
+}
+
+func libReplacementNativeIdentityProject(t *testing.T) string {
+ t.Helper()
+ root := ttscTypiaTestRepoRoot(t)
+ base := filepath.Join(root, "packages", "typia", "native", ".tmp-ttsc-typia-tests")
+ if err := os.MkdirAll(base, 0o755); err != nil {
+ t.Fatalf("mkdir temp base: %v", err)
+ }
+ dir, err := os.MkdirTemp(base, "lib-replacement-native-identity-")
+ if err != nil {
+ t.Fatalf("create temp fixture: %v", err)
+ }
+ t.Cleanup(func() {
+ _ = os.RemoveAll(dir)
+ })
+ for name, content := range map[string]string{
+ "tsconfig.json": libReplacementNativeIdentityTSConfig,
+ "node_modules/@typescript/lib-es2015/package.json": libReplacementNativeIdentityPackageJSON,
+ "node_modules/@typescript/lib-es2015/collection.d.ts": libReplacementNativeIdentityCollectionLib,
+ "src/input.ts": libReplacementNativeIdentitySource,
+ } {
+ path := filepath.Join(dir, filepath.FromSlash(name))
+ if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
+ t.Fatalf("mkdir fixture path %s: %v", filepath.Dir(path), err)
+ }
+ if err := os.WriteFile(path, []byte(content), 0o644); err != nil {
+ t.Fatalf("write fixture file %s: %v", path, err)
+ }
+ }
+ return dir
+}
+
+func libReplacementNativeIdentityRun(t *testing.T, project string, js string) (string, error) {
+ t.Helper()
+ node, err := exec.LookPath("node")
+ if err != nil {
+ t.Skip("node executable not found")
+ return "", nil
+ }
+ runtimeDir := filepath.Join(project, "runtime")
+ if err := os.MkdirAll(runtimeDir, 0o755); err != nil {
+ t.Fatalf("mkdir runtime dir: %v", err)
+ }
+ ttscTypiaTestWriteCommonRuntimeStubs(t, runtimeDir)
+ for name, content := range map[string]string{
+ "input.cjs": ttscTypiaTestRewriteCommonJS(t, js),
+ "run.cjs": libReplacementNativeIdentityRuntimeRunner,
+ } {
+ if err := os.WriteFile(filepath.Join(runtimeDir, name), []byte(content), 0o644); err != nil {
+ t.Fatalf("write runtime file %s: %v", name, err)
+ }
+ }
+ cmd := exec.Command(node, filepath.Join(runtimeDir, "run.cjs"))
+ cmd.Dir = runtimeDir
+ output, err := cmd.CombinedOutput()
+ return string(output), err
+}
+
+const libReplacementNativeIdentityTSConfig = `{
+ "compilerOptions": {
+ "target": "ES2022",
+ "module": "commonjs",
+ "moduleResolution": "bundler",
+ "ignoreDeprecations": "6.0",
+ "lib": ["ES2022"],
+ "types": [],
+ "libReplacement": true,
+ "esModuleInterop": true,
+ "strict": true,
+ "skipLibCheck": true
+ },
+ "include": ["src"]
+}
+`
+
+const libReplacementNativeIdentityPackageJSON = `{
+ "name": "@typescript/lib-es2015",
+ "version": "1.0.0"
+}
+`
+
+// libReplacementNativeIdentityCollectionLib is the replacement TypeScript loads
+// instead of its bundled `lib.es2015.collection.d.ts`. The collection
+// declarations are transcribed from that file so the rest of the standard
+// library still typechecks against them; `LibReplacementProbe` is the one
+// addition, and it is what proves the program loaded this file.
+const libReplacementNativeIdentityCollectionLib = `interface LibReplacementProbe {
+ libReplacementMarker: string;
+}
+
+interface Map {
+ clear(): void;
+ delete(key: K): boolean;
+ forEach(callbackfn: (value: V, key: K, map: Map) => void, thisArg?: any): void;
+ get(key: K): V | undefined;
+ has(key: K): boolean;
+ set(key: K, value: V): this;
+ readonly size: number;
+}
+
+interface MapConstructor {
+ new (): Map;
+ new (entries?: readonly (readonly [K, V])[] | null): Map;
+ readonly prototype: Map;
+}
+declare var Map: MapConstructor;
+
+interface ReadonlyMap {
+ forEach(callbackfn: (value: V, key: K, map: ReadonlyMap) => void, thisArg?: any): void;
+ get(key: K): V | undefined;
+ has(key: K): boolean;
+ readonly size: number;
+}
+
+interface WeakMap {
+ delete(key: K): boolean;
+ get(key: K): V | undefined;
+ has(key: K): boolean;
+ set(key: K, value: V): this;
+}
+
+interface WeakMapConstructor {
+ new (entries?: readonly (readonly [K, V])[] | null): WeakMap;
+ readonly prototype: WeakMap;
+}
+declare var WeakMap: WeakMapConstructor;
+
+interface Set {
+ add(value: T): this;
+ clear(): void;
+ delete(value: T): boolean;
+ forEach(callbackfn: (value: T, value2: T, set: Set) => void, thisArg?: any): void;
+ has(value: T): boolean;
+ readonly size: number;
+}
+
+interface SetConstructor {
+ new (values?: readonly T[] | null): Set;
+ readonly prototype: Set;
+}
+declare var Set: SetConstructor;
+
+interface ReadonlySet {
+ forEach(callbackfn: (value: T, value2: T, set: ReadonlySet) => void, thisArg?: any): void;
+ has(value: T): boolean;
+ readonly size: number;
+}
+
+interface WeakSet {
+ add(value: T): this;
+ delete(value: T): boolean;
+ has(value: T): boolean;
+}
+
+interface WeakSetConstructor {
+ new (values?: readonly T[] | null): WeakSet;
+ readonly prototype: WeakSet;
+}
+declare var WeakSet: WeakSetConstructor;
+`
+
+const libReplacementNativeIdentitySource = `import typia from "typia";
+
+export const createdIsProbe = typia.createIs();
+export const createdIsMap = typia.createIs