UNPKG

1.99 kBSource Map (JSON)View Raw
1{"version":3,"file":"convert-expression.js","sourceRoot":"","sources":["../../../src/lib/converter/convert-expression.ts"],"names":[],"mappings":";;AAAA,iCAAiC;AAUjC,SAAgB,mBAAmB,CAAC,IAAkE;IAClG,IAAI,IAAI,CAAC,WAAW,EAAE;QAClB,OAAO,iBAAiB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;KAC9C;SAAM;QACH,OAAO,SAAS,CAAC;KACpB;AACL,CAAC;AAND,kDAMC;AAED,SAAgB,iBAAiB,CAAC,UAAyB;IACvD,QAAQ,UAAU,CAAC,IAAI,EAAE;QACrB,KAAK,EAAE,CAAC,UAAU,CAAC,aAAa;YAC5B,OAAO,GAAG,GAA2B,UAAW,CAAC,IAAI,GAAG,GAAG,CAAC;QAChE,KAAK,EAAE,CAAC,UAAU,CAAC,cAAc;YAC7B,OAA+B,UAAW,CAAC,IAAI,CAAC;QACpD,KAAK,EAAE,CAAC,UAAU,CAAC,WAAW;YAC1B,OAAO,MAAM,CAAC;QAClB,KAAK,EAAE,CAAC,UAAU,CAAC,YAAY;YAC3B,OAAO,OAAO,CAAC;QACnB,KAAK,EAAE,CAAC,UAAU,CAAC,WAAW;YAC1B,OAAO,MAAM,CAAC;QAClB;YACI,OAAO,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,aAAa,EAAE,CAAC,CAAC;KAC7D;AACL,CAAC;AAfD,8CAeC","sourcesContent":["import * as ts from 'typescript';\nimport * as _ts from '../ts-internal';\n\n/**\n * Return the default value of the given node.\n *\n * @param node The TypeScript node whose default value should be extracted.\n * @returns The default value as a string.\n */\n\nexport function convertDefaultValue(node: ts.VariableDeclaration|ts.ParameterDeclaration|ts.EnumMember): string | undefined {\n if (node.initializer) {\n return convertExpression(node.initializer);\n } else {\n return undefined;\n }\n}\n\nexport function convertExpression(expression: ts.Expression): string {\n switch (expression.kind) {\n case ts.SyntaxKind.StringLiteral:\n return '\"' + (<ts.LiteralExpression> expression).text + '\"';\n case ts.SyntaxKind.NumericLiteral:\n return (<ts.LiteralExpression> expression).text;\n case ts.SyntaxKind.TrueKeyword:\n return 'true';\n case ts.SyntaxKind.FalseKeyword:\n return 'false';\n case ts.SyntaxKind.NullKeyword:\n return 'null';\n default:\n return expression.getText(expression.getSourceFile());\n }\n}\n"]}
\No newline at end of file