규칙 6.10
이 페이지에서

규칙 6.10

6장, 선언과 리소스 테스트

A local const binds its name once and leaves what it holds as writable as TypeScript does. A write into it (to a field, a component or an element, or by a method that writes its object) must change the value when the initializer builds one nothing else holds (new, an object literal, an array literal or a type’s constructor, alone or with methods called on it), the declaration being emitted as a var from then on; it must be refused with the remedy when the initializer may be a value something else holds (a name, a field, an element, a parameter, a function’s result). A const nothing writes into stays WGSL’s let. ref(v), or ref of a field or an element of v, is such a write when it is handed to a Ref<T> parameter (Rule 8.25), and is refused with the same remedy on a const whose value something else may hold.

규칙 본문과 그 아래 항목은 설계 문서에 적힌 컴파일러 원문이라 한국어 페이지에서도 영어로 둡니다.

근거

const v = new V(); v.bump() is how TypeScript is ordinarily written, since a const fixes the name and not the object; nothing else holds the object new built, so the local is that object, and a write through it changes what TypeScript changes. A const that copies a value another name holds is where the two would part: TypeScript’s write reaches the object both names hold, and a write here would reach the copy alone, so the front end asks which is meant, a let to write a copy or the write on the value itself. Before this rule every write through a const was refused, with let as the remedy. A struct is a value here, so const w = v and let w = v copy it, where TypeScript hands w the object v holds; a write through either name after the copy is not seen through the other, which Rule 7.2’s table records.

출처

ECMAScript let and const declarations (a const binding cannot be assigned again, and what it holds is not frozen); Value Declarations and var Declarations; Rule 8.10; surface §26.

검증 방식

테스트로 확인합니다. 테스트나 게이트 스크립트, CI 워크플로가 이 규칙을 가리키고, 아래 파일 가운데 하나라도 규칙을 더는 가리키지 않으면 추적 검사가 실패합니다.

컴파일러가 이 규칙을 적용하는 곳을 규칙이 직접 적은 내용입니다.

TS8005 CONST_ASSIGN for a write through a const that may hold a shared value ("v" is a const whose value may be one something else holds, which TypeScript would change with it and a copy here would not. Declare it with let to write a copy, or write through the value itself.), TS8035 CLASS_MEMBER for a method that writes its object called on one; pinned by src/compiler/ts/member-assign.test.ts, src/compiler/ts/class-methods.test.ts and src/compiler/ts/class-syntax.test.ts, which also holds the three CPU paths to one value for a write through a const that built its value; examples/class-parts.shade.ts in the compile gate.

커밋 c66579bf에서 이 규칙을 확인하는 파일입니다. 파일마다 규칙을 처음 가리키는 줄로 연결했습니다.

설명하는 절

커밋 c66579bf의 표면 문서에서 이 규칙을 설명하는 절입니다.

적용하는 오류 코드

규칙이 Enforced by 항목에서 가리키는 진단 코드와, 레지스트리 설명에서 이 규칙을 가리키는 진단 코드입니다.

TS8005 CONST_ASSIGN
const나 읽기 전용 리소스처럼 바뀔 수 없는 이름에 값을 대입합니다.
TS8035 CLASS_MEMBER
A class member shape the surface does not take, or a use of a member the class rules refuse, and a new that builds no class (Rule 8.13).

함께 보기

소스

커밋 c66579bf의 규칙 원문:

이 페이지 편집 문제 보고