Created
February 28, 2021 02:06
-
-
Save arturovt/499be9b8b92c21b80dae586e98f4fa22 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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