import { Vector } from "prelude-ts"; import * as P from "parsimmon"; import { NgScope } from "./view-parser"; import { NgFilter } from "./filters"; /** * Scope info used by ng-typeview. Directive authors can * consider it an opaque type (type synonym on purpose * so typedoc doesn't document it). */ export declare type NgScopeInfo = { readonly soFar: Vector; curScopeVars: string[]; }; /** * Companion object to assist typescript code generation. * It manages the scope behind the scenes so its state * changes as you call its methods. * If you do not let it know about variables you declare * in your typescript, there will be issues of '$scope.' * being prepended to the generated code when it shouldn't be. */ export declare class CodegenHelper { readonly ngScopeInfo: NgScopeInfo; private getNewVarName; readonly ngFilters: Vector; constructor(ngFilters: Vector, scope: Vector, getNewVarName: () => string); /** * Add scope accessors to a JS expression. For instance, * "data.name" will become "$scope.data.name" if the scope * has a field named 'data' * NOTE using an instance function so this will be properly * bound when used as a callback => * https://github.com/Microsoft/TypeScript/wiki/'this'-in-TypeScript#use-instance-functions * @param js the javascript from the angular view * @returns new source with the scope accessors added */ addScopeAccessors: (js: string) => string; /** * Get a new unique variable name * @returns new unique variable name */ getNewVariableName(): string; /** * Generate a TS expression declaring a variable of * the type and value that you give. Will automatically call * `addScopeAccessors` on the value. * @param type typescript type for the variable * @param val value for the variable * @returns typescript expression that registers the variable, as string. */ declareVariable(type: string, val: string): string; /** * You must register a variable name when you declare a variable * while generating code without going through [[generateVariable]] * or [[getNewVariableName]]. * Otherwise generation will add a `$scope.` accessor to it even though * it shouldn't. * Since `registerVariable` will return you the variable name you gave, * you can use this function as a pass-through, just wrap your var * name with this call. */ registerVariable(name: string): string; } /** * An angular filter expression. For instance * "data.items | orderBy: 'name'" * For that example, `expression` will contain "data.items" * and `filterCalls` will contain a single filter, "orderBy" with a parameter * of "name". */ export interface NgFilterExpression { /** * The base expression for the filter expression */ expression: string; /** * List of the filter calls applied to the base expression. */ filterCalls: NgFilterCall[]; } /** * An angular filter call. For instance "orderBy: 'name'". * For that example, `functionName` will contain "orderBy", * and `functionParameters` will contain a single parameter * of "name". */ export interface NgFilterCall { /** * The name of the filter function. */ functionName: string; /** * List of the function parameters. */ functionParameters: string[]; } /** * @hidden */ export declare function keyword(txt: string): P.Parser; /** * @hidden */ export declare function parseAtom(): P.Parser; /** * [Parsimmon](https://github.com/jneen/parsimmon) parser for angular filter * expressions. You can then use [[ngFilterExpressionToTypeScriptEmbedded]] * and [[ngFilterExpressionToTypeScriptStandalone]] to operate on the data. * @returns a [Parsimmon](https://github.com/jneen/parsimmon) Parser of [[NgFilterExpression]] */ export declare function parseNgFilterExpression(): P.Parser; /** * Convert an angular filter expression to typescript code. * For instance, "data.items | orderBy: 'name'" will become: * "f___orderBy($scope.data.items, 'name');". * Calls [[ngFilterExpressionToTypeScriptStandalone]] under the hood. * @param expr The angular filter expression * @param codegenHelpers Object which contains functions * to assist with typescript code generation. * @returns A typescript expression for type-checking the angular filters, * or the empty string in case of parse error. */ export declare function filterExpressionToTypescript(expr: string, codegenHelpers: CodegenHelper): string; /** * Convert a parsed angular filter expression to typescript code. * For instance, "data.items | orderBy: 'name'" will become: * "f___orderBy($scope.data.items, 'name');". * @param ngFilterExpr The parsed angular filter expression * @param codegenHelpers Object which contains functions * to assist with typescript code generation. * @returns A typescript expression for type-checking the angular filters, * or the empty string in case of parse error. */ export declare function ngFilterExpressionToTypeScriptStandalone(ngFilterExpr: NgFilterExpression, codegenHelpers: CodegenHelper): string; /** * Convert a parsed angular filter expression to typescript code. * For instance, "data.items | orderBy: 'name'" will become: * "f___orderBy($scope.data.items, 'name')". * Unlike [[ngFilterExpressionToTypeScriptStandalone]], this version will * generate typescript code to be reused by further code, not to be generated * standalone. For instance: * `ng-options="item.subItem as item.label for item in data.groups | orderBy:'labelSort'"` * In that case we can generate a typescript embeddable expression for: * `data.groups | orderBy:'labelSort'` and then include it in the rest of the * outer expression. * @param ngFilterExpr The parsed angular filter expression * @param codegenHelpers Code generation helpers * @returns A typescript expression for type-checking the angular filters, * or the empty string in case of parse error. */ export declare function ngFilterExpressionToTypeScriptEmbedded(ngFilterExpr: NgFilterExpression, codegenHelpers: CodegenHelper): string; /** * @hidden */ export declare function addScopeAccessors(scopes: Vector, _input: string): string;