Skip to content

Commit 170e789

Browse files
committed
Simplify few error creators
1 parent 3c18a03 commit 170e789

1 file changed

Lines changed: 30 additions & 57 deletions

File tree

src/transformation/utils/errors.ts

Lines changed: 30 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -99,85 +99,58 @@ export const UnsupportedFunctionWithoutBody = (node: ts.FunctionLikeDeclaration)
9999
new TranspileError("Functions with undefined bodies are not supported.", node);
100100

101101
export const UnsupportedNoSelfFunctionConversion = (node: ts.Node, name?: string) => {
102-
if (name) {
103-
return new TranspileError(
104-
`Unable to convert function with a 'this' parameter to function "${name}" with no 'this'. ` +
105-
`To fix, wrap in an arrow function, or declare with 'this: void'.`,
106-
node
107-
);
108-
} else {
109-
return new TranspileError(
110-
`Unable to convert function with a 'this' parameter to function with no 'this'. ` +
111-
`To fix, wrap in an arrow function, or declare with 'this: void'.`,
112-
node
113-
);
114-
}
102+
const nameReference = name ? ` '${name}'` : "";
103+
return new TranspileError(
104+
`Unable to convert function with a 'this' parameter to function${nameReference} with no 'this'. ` +
105+
`To fix, wrap in an arrow function, or declare with 'this: void'.`,
106+
node
107+
);
115108
};
116109

117110
export const UnsupportedSelfFunctionConversion = (node: ts.Node, name?: string) => {
118-
if (name) {
119-
return new TranspileError(
120-
`Unable to convert function with no 'this' parameter to function "${name}" with 'this'. ` +
121-
`To fix, wrap in an arrow function or declare with 'this: any'.`,
122-
node
123-
);
124-
} else {
125-
return new TranspileError(
126-
`Unable to convert function with no 'this' parameter to function with 'this'. ` +
127-
`To fix, wrap in an arrow function or declare with 'this: any'.`,
128-
node
129-
);
130-
}
111+
const nameReference = name ? ` '${name}'` : "";
112+
return new TranspileError(
113+
`Unable to convert function with no 'this' parameter to function${nameReference} with 'this'. ` +
114+
`To fix, wrap in an arrow function or declare with 'this: any'.`,
115+
node
116+
);
131117
};
132118

133119
export const UnsupportedOverloadAssignment = (node: ts.Node, name?: string) => {
134-
if (name) {
135-
return new TranspileError(
136-
`Unsupported assignment of function with different overloaded types for 'this' to "${name}". ` +
137-
`Overloads should all have the same type for 'this'.`,
138-
node
139-
);
140-
} else {
141-
return new TranspileError(
142-
`Unsupported assignment of function with different overloaded types for 'this'. ` +
143-
`Overloads should all have the same type for 'this'.`,
144-
node
145-
);
146-
}
120+
const nameReference = name ? ` to '${name}'` : "";
121+
return new TranspileError(
122+
`Unsupported assignment of function with different overloaded types for 'this'${nameReference}. ` +
123+
"Overloads should all have the same type for 'this'.",
124+
node
125+
);
147126
};
148127

149-
export const UnsupportedNonDestructuringLuaIterator = (node: ts.Node) => {
150-
return new TranspileError(
128+
export const UnsupportedNonDestructuringLuaIterator = (node: ts.Node) =>
129+
new TranspileError(
151130
"Unsupported use of lua iterator with '@tupleReturn' annotation in for...of statement. " +
152131
"You must use a destructuring statement to catch results from a lua iterator with " +
153132
"the '@tupleReturn' annotation.",
154133
node
155134
);
156-
};
157135

158-
export const UnresolvableRequirePath = (node: ts.Node, reason: string, path?: string) => {
159-
return new TranspileError(`${reason}. ` + `TypeScript path: ${path}.`, node);
160-
};
136+
export const UnresolvableRequirePath = (node: ts.Node, reason: string, path?: string) =>
137+
new TranspileError(`${reason}. TypeScript path: ${path}.`, node);
161138

162-
export const ReferencedBeforeDeclaration = (node: ts.Identifier) => {
163-
return new TranspileError(
139+
export const ReferencedBeforeDeclaration = (node: ts.Identifier) =>
140+
new TranspileError(
164141
`Identifier "${node.text}" was referenced before it was declared. The declaration ` +
165142
"must be moved before the identifier's use, or hoisting must be enabled.",
166143
node
167144
);
168-
};
169145

170-
export const UnsupportedObjectDestructuringInForOf = (node: ts.Node) => {
171-
return new TranspileError(`Unsupported object destructuring in for...of statement.`, node);
172-
};
146+
export const UnsupportedObjectDestructuringInForOf = (node: ts.Node) =>
147+
new TranspileError(`Unsupported object destructuring in for...of statement.`, node);
173148

174-
export const InvalidAmbientIdentifierName = (node: ts.Identifier) => {
175-
return new TranspileError(
149+
export const InvalidAmbientIdentifierName = (node: ts.Identifier) =>
150+
new TranspileError(
176151
`Invalid ambient identifier name "${node.text}". Ambient identifiers must be valid lua identifiers.`,
177152
node
178153
);
179-
};
180154

181-
export const InvalidForRangeCall = (node: ts.Node, message: string) => {
182-
return new TranspileError(`Invalid @forRange call: ${message}`, node);
183-
};
155+
export const InvalidForRangeCall = (node: ts.Node, message: string) =>
156+
new TranspileError(`Invalid @forRange call: ${message}`, node);

0 commit comments

Comments
 (0)