Fixed compilation for TS 4.x

master
WolverinDEV 2021-04-27 17:00:45 +02:00
parent a23f426b7b
commit 32de3542df
2 changed files with 25 additions and 22 deletions

View File

@ -121,17 +121,20 @@ export function transform(config: Configuration, context: ts.TransformationConte
config.variables.declareFiles = config.variables.declareFiles || (config.optimized ? "f" : "declare_files"); config.variables.declareFiles = config.variables.declareFiles || (config.optimized ? "f" : "declare_files");
config.variables.declarations = config.variables.declarations || (config.optimized ? "d" : "definitions"); config.variables.declarations = config.variables.declarations || (config.optimized ? "d" : "definitions");
const nodeFactory = ts.factory;
//Initialize nodes //Initialize nodes
const extraNodes = []; const extraNodes = [];
{ if(config.cacheTranslations) {
/* This doesn't yet work with TS 4.X */
cache.nodes = {} as any; cache.nodes = {} as any;
if(config.useWindow) { if(config.useWindow) {
const window = ts.createIdentifier("window"); const window = nodeFactory.createIdentifier("window");
const translationMap = ts.createPropertyAccess(window, ts.createIdentifier(config.variables.base)); const translationMap = nodeFactory.createPropertyAccessExpression(window, nodeFactory.createIdentifier(config.variables.base));
const newTranslations = ts.createAssignment(translationMap, ts.createObjectLiteral()); const newTranslations = nodeFactory.createAssignment(translationMap, nodeFactory.createObjectLiteralExpression());
extraNodes.push(ts.createParen( extraNodes.push(nodeFactory.createParenthesizedExpression(
ts.createBinary(translationMap, ts.SyntaxKind.BarBarToken, newTranslations) nodeFactory.createBinaryExpression(translationMap, ts.SyntaxKind.BarBarToken, newTranslations)
)); ));
cache.nodes = { cache.nodes = {
@ -139,24 +142,24 @@ export function transform(config: Configuration, context: ts.TransformationConte
}; };
} else if(config.module) { } else if(config.module) {
cache.nodes = { cache.nodes = {
translationMap: ts.createIdentifier(config.variables.base) translationMap: nodeFactory.createIdentifier(config.variables.base)
}; };
extraNodes.push(( extraNodes.push((
ts.createVariableDeclarationList([ nodeFactory.createVariableDeclarationList([
ts.createVariableDeclaration(config.variables.base, undefined, ts.createObjectLiteral()) nodeFactory.createVariableDeclaration(config.variables.base, undefined, undefined, nodeFactory.createObjectLiteralExpression())
], ts.NodeFlags.Const) ], ts.NodeFlags.Const)
), ts.createToken(SyntaxKind.SemicolonToken)); ), nodeFactory.createToken(SyntaxKind.SemicolonToken));
} else { } else {
const variableMap = ts.createIdentifier(config.variables.base); const variableMap = nodeFactory.createIdentifier(config.variables.base);
const inlineIf = ts.createBinary( const inlineIf = nodeFactory.createBinaryExpression(
ts.createBinary( nodeFactory.createBinaryExpression(
ts.createTypeOf(variableMap), nodeFactory.createTypeOfExpression(variableMap),
SyntaxKind.ExclamationEqualsEqualsToken, SyntaxKind.ExclamationEqualsEqualsToken,
ts.createLiteral("undefined") nodeFactory.createStringLiteral("undefined")
), ),
ts.SyntaxKind.BarBarToken, ts.SyntaxKind.BarBarToken,
ts.createAssignment(variableMap, ts.createObjectLiteral()) nodeFactory.createAssignment(variableMap, nodeFactory.createObjectLiteralExpression())
); );
cache.nodes = { cache.nodes = {
@ -277,13 +280,13 @@ export function visitNode(config: Configuration, cache: VolatileTransformConfig,
return node; return node;
} }
const variableName = ts.createIdentifier(cache.nameGenerator(config, node, object.text || object.getText(sourceFile))); const variableName = ts.factory.createIdentifier(cache.nameGenerator(config, node, object.text || object.getText(sourceFile)));
const variableInit = ts.createPropertyAccess(cache.nodes.translationMap, variableName); const variableInit = ts.factory.createPropertyAccessExpression(cache.nodes.translationMap, variableName);
const variable = ts.createPropertyAccess(cache.nodes.translationMap, variableName); const variable = ts.factory.createPropertyAccessExpression(cache.nodes.translationMap, variableName);
const newVariable = ts.createAssignment(variable, call); const newVariable = ts.factory.createAssignment(variable, call);
return ts.createBinary(variableInit, ts.SyntaxKind.BarBarToken, newVariable); return ts.factory.createBinaryExpression(variableInit, ts.SyntaxKind.BarBarToken, newVariable);
} else if(node.kind === SyntaxKind.JsxElement) { } else if(node.kind === SyntaxKind.JsxElement) {
const element = node as ts.JsxElement; const element = node as ts.JsxElement;
const tag = element.openingElement.tagName as ts.Identifier; const tag = element.openingElement.tagName as ts.Identifier;

2
vendor/xbbcode vendored

@ -1 +1 @@
Subproject commit e61434dc048c5de71c31ca3a11f7db97217b0231 Subproject commit 13eb8766a066694edd40acac2abc1b5847edf50b