Rule 3.1
Chapter 3, Textual structure and names Test
A shader file must begin with the directive "use typeshade" as its first statement.
The rule text and the parts under it are the compiler's own English, as the design document writes them.
Rationale
the directive is what tells the compiler and the language service that the file is a shader and not host code; the bundler and a host program’s tsconfig read the file’s name first, which Rule 3.8 fixes as *.shade.ts, and the directive is what they check it against.
Derives from
surface §1 and src/compiler/ts/source-file.ts.
How it is verified
Checked by a test. A test, a gate script or a CI workflow names this rule, and the traceability check fails when a file listed below stops naming it.
Where the rule says the compiler enforces it:
TS8001 MISSING_DIRECTIVE, which yields an otherwise empty result, for a file with no directive at all; TS8069 MISPLACED_DIRECTIVE on a directive after another top-level statement, another string directive included, with the rest of the file still checked (#200, proposal 0012), pinned by src/compiler/ts/directive-placement.test.ts.
The files that verify it at commit af54ddad5, each at the first line that names the rule:
Explained in
The sections of the surface document that explain this rule, at commit af54ddad5:
Error codes that enforce it
The diagnostic codes the rule names under Enforced by, or whose registry text names the rule:
-
TS8001MISSING_DIRECTIVE - A file compiled as TypeShade that has no
"use typeshade"directive at all. -
TS8069MISPLACED_DIRECTIVE - A
"use typeshade"directive after another top-level statement (Rule 3.1). In ECMAScript a directive is only a leading string statement, so TypeScript reads a late one as an ordinary string. The fix is to move the directive, not to add one; a file with no directive at all isMISSING_DIRECTIVE.
See also
Source
The rule at commit af54ddad5:
docs/language-design.md:232(the design document)reqs/rules/RULE-0301.md(its traceability item)