규칙 3.9
3장, 텍스트 구조와 이름 테스트
A shader file may import what another shader file exports, by a relative specifier or, from a package, by the package’s name; the file a compile starts from and every shader file it imports, directly or through another, are one program, which emits one module, and each file keeps the scope TypeScript gives it.
Every declaration a file can make at the top level can be exported and imported, by name (import { a, b as c }), as a type (import type), through a module namespace read one name at a time (import * as ns, then ns.f), and through a re-export (export { a } from, export { a as b } from, export * from); the module holds the entry’s declarations and what it re-exports and, of each imported file, what those reach, so an imported file’s own entry points are not in it.
A relative specifier resolves against the importing file, with .js and .mjs read as .ts and .ts appended to any other path; any other names a package, name or @scope/name and an optional subpath, which is the first node_modules/<name>/package.json from the importing file’s directory up: with exports, the subpath is looked up in it as Node looks it up, with the conditions typeshade, import and default tried in that order, and without exports, a subpath names a file of the package by the relative rule; both by the one rule the language service resolves an import by.
A program holds one copy of a package version: a file of a package is one file by the package’s name, its version and its path in the package, however many paths reach it.
An import the compiler does not follow must be refused with TS8072, on the import: a path that names no file or one the compile cannot read, a file that does not begin with the directive (Rule 3.1), a package no node_modules holds, a subpath a package’s exports does not name or maps to null, a package’s name alone when it has no exports, a # specifier of a package’s import map, a specifier that is neither relative nor a package name, a name the file does not export, a default import or export, an import that names nothing, import(...) and require, and a module namespace used as a value; a use of what it would have bound reports nothing more (Rule 12.4).
규칙 본문과 그 아래 항목은 설계 문서에 적힌 컴파일러 원문이라 한국어 페이지에서도 영어로 둡니다.
근거
TypeShade code is shared the way TypeScript code is (docs/dx.md principle 8), and the editor’s TypeScript half reads an import as TypeScript does, so a compiler that refused one would give a second answer about the same program (Rule 12.7).
A module is one WGSL module whichever file declared what, so scope is TypeScript’s and only the emitted names are the module’s (Rule 3.2).
출처
changes 0022 and 0024 in changes/; #187; ECMAScript Modules, as TypeScript checks them; Node’s resolution algorithm (PACKAGE_RESOLVE, PACKAGE_EXPORTS_RESOLVE) for a package; docs/roadmap.md item X6.
검증 방식
테스트로 확인합니다. 테스트나 게이트 스크립트, CI 워크플로가 이 규칙을 가리키고, 아래 파일 가운데 하나라도 규칙을 더는 가리키지 않으면 추적 검사가 실패합니다.
컴파일러가 이 규칙을 적용하는 곳을 규칙이 직접 적은 내용입니다.
linkProgram in src/compiler/ts/link.ts, which compileTsSource runs for a file that imports, and so compile(), the Vite plugin, tshc check and the language service; resolveSpecifier in src/compiler/ts/specifier.ts, the one rule both halves resolve a specifier by, pinned by src/compiler/ts/specifier.test.ts; TS8072 IMPORT; pinned by src/compiler/ts/link.test.ts, which holds compile() and the language service to one answer on each program and each refusal, a package’s included; and by the import path of the user journeys (scripts/user-journey.ts), whose module imports a package npm installed.
커밋 26de7be8에서 이 규칙을 확인하는 파일입니다. 파일마다 규칙을 처음 가리키는 줄로 연결했습니다.
설명하는 절
커밋 26de7be8의 표면 문서에서 이 규칙을 설명하는 절입니다.
적용하는 오류 코드
규칙이 Enforced by 항목에서 가리키는 진단 코드와, 레지스트리 설명에서 이 규칙을 가리키는 진단 코드입니다.
-
TS8072IMPORT - An import the compiler does not follow (Rule 3.9, surface §68, proposals 0022 and 0024): a path that names no file or one this compile cannot read, a file that is not a shader module, a package no
node_modulesholds, a subpath a package'sexportsdoes not name, a package's name alone when it has noexports, a#specifier or one that is neither relative nor a package name, a name the module does not export, and the forms a shader module has no use for (a default import or export, an import that names nothing,import(...),require, a module namespace used as a value).
함께 보기
소스
커밋 26de7be8의 규칙 원문:
docs/language-design.md:187(설계 문서)reqs/rules/RULE-0309.md(추적 항목)