[Timelion] Build optimization - move parser_async to chunk (#93766)

* [Timelion] Build optimization - move parser_async to chunk

* Update parser_async.ts
This commit is contained in:
Alexey Antonov 2021-03-05 19:52:50 +03:00 committed by GitHub
parent 542d66643e
commit a3b848a5be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 6 deletions

View file

@ -0,0 +1,15 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { ParsedExpression } from './parser';
/** Build optimizations, we want to exclude the parser from the main bundle **/
export const parseTimelionExpressionAsync = async (input: string): Promise<ParsedExpression> => {
const { parseTimelionExpression } = await import('../common/parser');
return parseTimelionExpression(input);
};

View file

@ -9,8 +9,8 @@
import { startsWith } from 'lodash';
import { i18n } from '@kbn/i18n';
import { monaco } from '@kbn/monaco';
import {
parseTimelionExpression,
import { parseTimelionExpressionAsync } from '../../common/parser_async';
import type {
ParsedExpression,
TimelionExpressionArgument,
ExpressionLocation,
@ -128,7 +128,7 @@ export async function suggest(
argValueSuggestions: ArgValueSuggestions
) {
try {
const result = parseTimelionExpression(expression);
const result = await parseTimelionExpressionAsync(expression);
return await extractSuggestionsFromParsedResult(
result,

View file

@ -15,7 +15,7 @@ import { TimelionVisDependencies } from './plugin';
import { toExpressionAst } from './to_ast';
import { getIndexPatterns } from './helpers/plugin_services';
import { parseTimelionExpression } from '../common/parser';
import { parseTimelionExpressionAsync } from '../common/parser_async';
import { VIS_EVENT_TO_TRIGGER, VisParams } from '../../visualizations/public';
@ -50,9 +50,9 @@ export function getTimelionVisDefinition(dependencies: TimelionVisDependencies)
getSupportedTriggers: () => {
return [VIS_EVENT_TO_TRIGGER.applyFilter];
},
getUsedIndexPattern: (params: VisParams) => {
getUsedIndexPattern: async (params: VisParams) => {
try {
const args = parseTimelionExpression(params.expression)?.args ?? [];
const args = (await parseTimelionExpressionAsync(params.expression))?.args ?? [];
const indexArg = args.find(
({ type, name, function: fn }) => type === 'namedArg' && fn === 'es' && name === 'index'
);