• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import ts from 'typescript';
17
18import { BUILD_OFF } from './pre_define';
19import {
20  resetLog,
21  transformLog
22} from './process_ui_syntax';
23import {
24  propertyCollection,
25  linkCollection,
26  processSystemApi
27} from './validate_ui_syntax';
28import {
29  LogInfo,
30  emitLogInfo,
31  componentInfo
32} from './utils';
33import { resetComponentCollection } from './validate_ui_syntax';
34import { abilityConfig } from '../main';
35
36module.exports = function resultProcess(source: string, map: any): void {
37  process.env.compiler = BUILD_OFF;
38  source = processSystemApi(source, true);
39  if (/\.ets$/.test(this.resourcePath)) {
40    componentInfo.id = 0;
41    propertyCollection.clear();
42    linkCollection.clear();
43    resetComponentCollection();
44    if (transformLog && transformLog.errors.length) {
45      const sourceFile: ts.SourceFile = transformLog.sourceFile;
46      const logInfos: LogInfo[] = transformLog.errors.map((item) => {
47        if (item.pos) {
48          if (!item.column || !item.line) {
49            const posOfNode: ts.LineAndCharacter = sourceFile.getLineAndCharacterOfPosition(item.pos);
50            item.line = posOfNode.line + 1;
51            item.column = posOfNode.character + 1;
52          }
53        } else {
54          item.line = item.line || undefined;
55          item.column = item.column || undefined;
56        }
57        item.fileName = item.fileName || sourceFile.fileName;
58        return item;
59      });
60      emitLogInfo(this, logInfos);
61      resetLog();
62    }
63  }
64  if ([abilityConfig.abilityEntryFile].concat(abilityConfig.projectAbilityPath).concat(abilityConfig.testRunnerFile).includes(this.resourcePath)) {
65    source = source.replace(/exports\.default/, 'globalThis.exports.default');
66  }
67
68  this.callback(null, source, map);
69};
70