Skip to content

Instantly share code, notes, and snippets.

@arturovt
Created February 28, 2021 02:06
Show Gist options
  • Save arturovt/499be9b8b92c21b80dae586e98f4fa22 to your computer and use it in GitHub Desktop.
Save arturovt/499be9b8b92c21b80dae586e98f4fa22 to your computer and use it in GitHub Desktop.
import * as ts from 'typescript';
import { PLATFORM } from '@ngtools/webpack';
const replaceIsPlatformCallsTransformerFactory: ts.TransformerFactory<ts.SourceFile> = (
context: ts.TransformationContext,
) => (sourceFile: ts.SourceFile) => {
const visitCallExpression: ts.Visitor = (node: ts.Node) => {
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
// If it's a call expression like `isPlatformServer(platformId)`.
if (node.expression.escapedText === 'isPlatformServer') {
return ts.factory.createFalse();
} else if (node.expression.escapedText === 'isPlatformBrowser') {
return ts.factory.createTrue();
}
}
return ts.visitEachChild(node, visitCallExpression, context);
};
return ts.visitEachChild(sourceFile, visitCallExpression, context);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment