@@ -4,13 +4,13 @@ import { assert, getOrUpdate, isNonNull } from "../../../utils";
44import { FunctionVisitor , TransformationContext } from "../../context" ;
55import { AnnotationKind , getTypeAnnotations } from "../../utils/annotations" ;
66import {
7- ForbiddenLuaTableNonDeclaration ,
8- InvalidExportsExtension ,
9- InvalidExtendsExtension ,
10- InvalidExtendsLuaTable ,
11- InvalidExtensionMetaExtension ,
12- MissingMetaExtension ,
13- } from "../../utils/errors " ;
7+ extensionAndMetaExtensionConflict ,
8+ extensionCannotExport ,
9+ extensionCannotExtend ,
10+ metaExtensionMissingExtends ,
11+ luaTableMustBeAmbient ,
12+ luaTableCannotBeExtended ,
13+ } from "../../utils/diagnostics " ;
1414import {
1515 createDefaultExportIdentifier ,
1616 createExportedIdentifier ,
@@ -96,15 +96,16 @@ export function transformClassDeclaration(
9696 const isMetaExtension = annotations . has ( AnnotationKind . MetaExtension ) ;
9797
9898 if ( isExtension && isMetaExtension ) {
99- throw InvalidExtensionMetaExtension ( classDeclaration ) ;
99+ context . diagnostics . push ( extensionAndMetaExtensionConflict ( classDeclaration ) ) ;
100100 }
101101
102102 if ( ( isExtension || isMetaExtension ) && getIdentifierExportScope ( context , className ) !== undefined ) {
103103 // Cannot export extension classes
104- throw InvalidExportsExtension ( classDeclaration ) ;
104+ context . diagnostics . push ( extensionCannotExport ( classDeclaration ) ) ;
105105 }
106106
107107 // Get type that is extended
108+ const extendsTypeNode = getExtendedTypeNode ( context , classDeclaration ) ;
108109 const extendsType = getExtendedType ( context , classDeclaration ) ;
109110
110111 if ( extendsType ) {
@@ -115,21 +116,20 @@ export function transformClassDeclaration(
115116 // Non-extensions cannot extend extension classes
116117 const extendsAnnotations = getTypeAnnotations ( context , extendsType ) ;
117118 if ( extendsAnnotations . has ( AnnotationKind . Extension ) || extendsAnnotations . has ( AnnotationKind . MetaExtension ) ) {
118- throw InvalidExtendsExtension ( classDeclaration ) ;
119+ context . diagnostics . push ( extensionCannotExtend ( classDeclaration ) ) ;
119120 }
120121 }
121122
122123 // You cannot extend LuaTable classes
123124 if ( extendsType ) {
124125 const annotations = getTypeAnnotations ( context , extendsType ) ;
125126 if ( annotations . has ( AnnotationKind . LuaTable ) ) {
126- throw InvalidExtendsLuaTable ( classDeclaration ) ;
127+ context . diagnostics . push ( luaTableCannotBeExtended ( extendsTypeNode ! ) ) ;
127128 }
128129 }
129130
130- // LuaTable classes must be ambient
131131 if ( annotations . has ( AnnotationKind . LuaTable ) && ! isAmbientNode ( classDeclaration ) ) {
132- throw ForbiddenLuaTableNonDeclaration ( classDeclaration ) ;
132+ context . diagnostics . push ( luaTableMustBeAmbient ( classDeclaration ) ) ;
133133 }
134134
135135 // Get all properties with value
@@ -143,30 +143,30 @@ export function transformClassDeclaration(
143143
144144 // Overwrite the original className with the class we are overriding for extensions
145145 if ( isMetaExtension ) {
146- if ( ! extendsType ) {
147- throw MissingMetaExtension ( classDeclaration ) ;
148- }
149-
150- const extendsName = lua . createStringLiteral ( extendsType . symbol . name as string ) ;
151- className = lua . createIdentifier ( "__meta__" + extendsName . value ) ;
152-
153- // local className = debug.getregistry()["extendsName"]
154- const assignDebugCallIndex = lua . createVariableDeclarationStatement (
155- className ,
156- lua . createTableIndexExpression (
157- lua . createCallExpression (
158- lua . createTableIndexExpression (
159- lua . createIdentifier ( "debug" ) ,
160- lua . createStringLiteral ( "getregistry" )
146+ if ( extendsType ) {
147+ const extendsName = lua . createStringLiteral ( extendsType . symbol . name ) ;
148+ className = lua . createIdentifier ( "__meta__" + extendsName . value ) ;
149+
150+ // local className = debug.getregistry()["extendsName"]
151+ const assignDebugCallIndex = lua . createVariableDeclarationStatement (
152+ className ,
153+ lua . createTableIndexExpression (
154+ lua . createCallExpression (
155+ lua . createTableIndexExpression (
156+ lua . createIdentifier ( "debug" ) ,
157+ lua . createStringLiteral ( "getregistry" )
158+ ) ,
159+ [ ]
161160 ) ,
162- [ ]
161+ extendsName
163162 ) ,
164- extendsName
165- ) ,
166- classDeclaration
167- ) ;
163+ classDeclaration
164+ ) ;
168165
169- result . push ( assignDebugCallIndex ) ;
166+ result . push ( assignDebugCallIndex ) ;
167+ } else {
168+ context . diagnostics . push ( metaExtensionMissingExtends ( classDeclaration ) ) ;
169+ }
170170 }
171171
172172 if ( extensionDirective !== undefined ) {
0 commit comments