mirror of
https://github.com/openharmony/developtools_ace-ets2bundle.git
synced 2026-07-20 00:54:09 -04:00
!91 update code from wagner.
Merge pull request !91 from lihong/newmaster_1222
This commit is contained in:
@@ -49,6 +49,7 @@ function generateTargetFile(filePath, output) {
|
||||
fs.writeFile(fileName, newContent, err => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "sheet",
|
||||
"name": "Sheet",
|
||||
"children": ["Section"],
|
||||
"attrs": []
|
||||
}
|
||||
+1
-1
@@ -197,4 +197,4 @@ exports.loadEntryObj = loadEntryObj;
|
||||
exports.readAppResource = readAppResource;
|
||||
exports.resources = resources;
|
||||
exports.loadWorker = loadWorker;
|
||||
exports.abilityConfig = abilityConfig;
|
||||
exports.abilityConfig = abilityConfig;
|
||||
Generated
+270
-270
File diff suppressed because it is too large
Load Diff
@@ -42,4 +42,4 @@ struct HomeComponent {
|
||||
}
|
||||
.height(500)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,4 +31,4 @@ struct MyComponent1 {
|
||||
Text(this.value3)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,4 +60,4 @@ struct ListRootView {
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,4 +32,4 @@ struct MyStateComponent {
|
||||
build() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,4 +27,4 @@ struct MyLinkComponent {
|
||||
build() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,4 +27,4 @@ struct MyPropComponent {
|
||||
build() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,4 +59,4 @@ struct CalendarDemo {
|
||||
(item: Month) => (item.year * 12 + item.month).toString()) // outer ForEach
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,4 +30,4 @@ struct UserView1 {
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,4 +33,4 @@ struct HomeComponent {
|
||||
}
|
||||
.height(500)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,4 +48,4 @@ struct LinkTest {
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,4 +45,4 @@ struct ChildB {
|
||||
}
|
||||
.onClick(() => this.counterRef += 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,4 +27,4 @@ struct MyComponent3 {
|
||||
Text(this.value3)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,4 +27,4 @@ struct MyComponent3 {
|
||||
Text(this.value3)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,4 +27,4 @@ struct MyComponent4 {
|
||||
Text(this.value3)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,4 +35,4 @@ struct MyComponent5 {
|
||||
Banner()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,4 +35,4 @@ struct MyComponent6 {
|
||||
new Banner()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
*
|
||||
* ACE @ Web Helsinki
|
||||
*
|
||||
|
||||
*/
|
||||
|
||||
const enum FlexAlign {
|
||||
|
||||
@@ -80,4 +80,4 @@ struct UserView {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,4 +145,4 @@ struct TestView {
|
||||
}
|
||||
.alignItems(HorizontalAlign.Center)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,4 +103,4 @@ struct ShufflingContainer {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,4 +18,4 @@
|
||||
struct MyComponent7 {
|
||||
build() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,4 +16,4 @@
|
||||
struct MyComponent8 {
|
||||
build() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
* https://rnd-gitlab-eu-c.huawei.com/zidanehbs/ace/ace/-/blob/fin-hmf-dev-ace-diff-clean/samples/common/res/hi_topapp/assets/js/default/acediff/todoListForEach.js
|
||||
* This is the ouput the eDSL transpiler should generate.
|
||||
*/
|
||||
|
||||
let tasks: Array<any> = [
|
||||
{ label: "Wash the car" },
|
||||
{ label: "Buy some milk" },
|
||||
|
||||
@@ -50,7 +50,7 @@ configure({
|
||||
});
|
||||
export const logger = getLogger('ETS');
|
||||
|
||||
const props: string[] = [];
|
||||
export const props: string[] = [];
|
||||
const GLOBAL_COMMON_MODULE_CACHE: string = `
|
||||
globalThis["__common_module_cache__"] = globalThis["__common_module_cache__"] || {};
|
||||
globalThis["webpackChunkcompilier"].forEach((item)=> {
|
||||
@@ -252,7 +252,7 @@ export class ResultStates {
|
||||
}
|
||||
}
|
||||
private validateError(message: string): boolean {
|
||||
const propInfoReg: RegExp = /Cannot find name\s*'(\$?[_a-zA-Z0-9]+)'/;
|
||||
const propInfoReg: RegExp = /Cannot find name\s*'(\$?\$?[_a-zA-Z0-9]+)'/;
|
||||
const componentNameReg: RegExp = /'typeof\s*(\$?[_a-zA-Z0-9]+)' is not callable/;
|
||||
const stateInfoReg: RegExp = /Property\s*'(\$[_a-zA-Z0-9]+)' does not exist on type/;
|
||||
const extendInfoReg: RegExp =
|
||||
|
||||
@@ -184,3 +184,10 @@ export const BUILD_SHARE_PATH: string = '../share';
|
||||
export const THIS: string = 'this';
|
||||
export const STYLES: string = 'Styles';
|
||||
export const VISUAL_STATE: string = 'visualState';
|
||||
export const VIEW_STACK_PROCESSOR: string = 'ViewStackProcessor';
|
||||
|
||||
export const BIND_POPUP: string = 'bindPopup';
|
||||
export const $$_VALUE: string = 'value';
|
||||
export const $$_CHANGE_EVENT: string = 'changeEvent';
|
||||
export const $$_THIS: string = '$$this';
|
||||
export const $$_NEW_VALUE: string = 'newValue';
|
||||
|
||||
@@ -46,7 +46,13 @@ import {
|
||||
COMPONENT_DEBUGLINE_FUNCTION,
|
||||
ATTRIBUTE_STATESTYLES,
|
||||
THIS,
|
||||
VISUAL_STATE
|
||||
VISUAL_STATE,
|
||||
VIEW_STACK_PROCESSOR,
|
||||
BIND_POPUP,
|
||||
$$_VALUE,
|
||||
$$_CHANGE_EVENT,
|
||||
$$_THIS,
|
||||
$$_NEW_VALUE
|
||||
} from './pre_define';
|
||||
import {
|
||||
INNER_COMPONENT_NAMES,
|
||||
@@ -72,6 +78,7 @@ import {
|
||||
} from './utils';
|
||||
import { projectConfig } from '../main';
|
||||
import { transformLog } from './process_ui_syntax';
|
||||
import { props } from './compile_info';
|
||||
|
||||
export const appComponentCollection: Set<string> = new Set();
|
||||
|
||||
@@ -479,6 +486,44 @@ export function bindComponentAttr(node: ts.ExpressionStatement, identifierNode:
|
||||
}
|
||||
}
|
||||
|
||||
function createArrowFunctionFor$$ ($$varExp: ts.Expression): ts.ArrowFunction {
|
||||
return ts.factory.createArrowFunction(
|
||||
undefined, undefined,
|
||||
[ts.factory.createParameterDeclaration(
|
||||
undefined, undefined, undefined,
|
||||
ts.factory.createIdentifier($$_NEW_VALUE),
|
||||
undefined, undefined, undefined
|
||||
)],
|
||||
undefined,
|
||||
ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
|
||||
ts.factory.createBlock(
|
||||
[ts.factory.createExpressionStatement(ts.factory.createBinaryExpression(
|
||||
$$varExp,
|
||||
ts.factory.createToken(ts.SyntaxKind.EqualsToken),
|
||||
ts.factory.createIdentifier($$_NEW_VALUE)
|
||||
))],
|
||||
false
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function updateArgumentFor$$(argument: any): ts.Expression {
|
||||
if (ts.isElementAccessExpression(argument)) {
|
||||
return ts.factory.updateElementAccessExpression
|
||||
(argument, updateArgumentFor$$(argument.expression), argument.argumentExpression);
|
||||
} else if (ts.isIdentifier(argument)) {
|
||||
props.push(argument.getText());
|
||||
if (argument.getText() === $$_THIS) {
|
||||
return ts.factory.createThis();
|
||||
} else if (argument.getText().match(/^\$\$(.|\n)+/)) {
|
||||
return ts.factory.createIdentifier(argument.getText().replace(/\$\$/, ''));
|
||||
}
|
||||
} else if (ts.isPropertyAccessExpression(argument)) {
|
||||
return ts.factory.updatePropertyAccessExpression
|
||||
(argument, updateArgumentFor$$(argument.expression), argument.name);
|
||||
}
|
||||
}
|
||||
|
||||
function addComponentAttr(temp: any, node: ts.Identifier, lastStatement: any,
|
||||
statements: ts.Statement[], identifierNode: ts.Identifier, log: LogInfo[],
|
||||
isStylesAttr): void {
|
||||
@@ -520,6 +565,15 @@ function addComponentAttr(temp: any, node: ts.Identifier, lastStatement: any,
|
||||
GLOBAL_STYLE_FUNCTION.get(propName) || INNER_STYLE_FUNCTION.get(propName);
|
||||
bindComponentAttr(styleBlock.statements[0] as ts.ExpressionStatement, identifierNode,
|
||||
statements, log, false, true);
|
||||
} else if (propName === BIND_POPUP && temp.arguments.length === 2 &&
|
||||
temp.arguments[0].getText().match(/^\$\$(.|\n)+/)) {
|
||||
const argumentsArr: ts.Expression[] = [];
|
||||
const varExp: ts.Expression = updateArgumentFor$$(temp.arguments[0]);
|
||||
argumentsArr.push(generateObjectFor$$(varExp));
|
||||
argumentsArr.push(temp.arguments[1]);
|
||||
statements.push(ts.factory.createExpressionStatement(
|
||||
createFunction(identifierNode, node, argumentsArr)));
|
||||
lastStatement.kind = true;
|
||||
} else {
|
||||
if (isStylesAttr && !COMMON_ATTRS.has(propName)) {
|
||||
validateStateStyleSyntax(temp, log);
|
||||
@@ -530,14 +584,30 @@ function addComponentAttr(temp: any, node: ts.Identifier, lastStatement: any,
|
||||
}
|
||||
}
|
||||
|
||||
function createViewStackProcessor(item: any, endViewStack: boolean) {
|
||||
const argument: ts.StringLiteral[] = []
|
||||
function generateObjectFor$$(varExp: ts.Expression): ts.ObjectLiteralExpression {
|
||||
return ts.factory.createObjectLiteralExpression(
|
||||
[
|
||||
ts.factory.createPropertyAssignment(
|
||||
ts.factory.createIdentifier($$_VALUE),
|
||||
varExp
|
||||
),
|
||||
ts.factory.createPropertyAssignment(
|
||||
ts.factory.createIdentifier($$_CHANGE_EVENT),
|
||||
createArrowFunctionFor$$(varExp)
|
||||
)
|
||||
],
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
function createViewStackProcessor(item: any, endViewStack: boolean): ts.ExpressionStatement {
|
||||
const argument: ts.StringLiteral[] = [];
|
||||
if (!endViewStack && item.name) {
|
||||
argument.push(ts.factory.createStringLiteral(item.name.getText()));
|
||||
}
|
||||
return ts.factory.createExpressionStatement(ts.factory.createCallExpression(
|
||||
ts.factory.createPropertyAccessExpression(
|
||||
ts.factory.createIdentifier(GLOBAL_CONTEXT),
|
||||
ts.factory.createIdentifier(VIEW_STACK_PROCESSOR),
|
||||
ts.factory.createIdentifier(VISUAL_STATE)
|
||||
),
|
||||
undefined,
|
||||
@@ -546,7 +616,7 @@ function createViewStackProcessor(item: any, endViewStack: boolean) {
|
||||
}
|
||||
|
||||
function traverseStateStylesAttr(temp: any, statements: ts.Statement[],
|
||||
identifierNode: ts.Identifier, log: LogInfo[]) {
|
||||
identifierNode: ts.Identifier, log: LogInfo[]): void {
|
||||
temp.arguments[0].properties.reverse().forEach((item: ts.PropertyAssignment) => {
|
||||
if (ts.isPropertyAccessExpression(item.initializer) &&
|
||||
item.initializer.expression.getText() === THIS &&
|
||||
@@ -770,7 +840,7 @@ function validateExtendParameterCount(temp: any, identifierNode: ts.Identifier,
|
||||
}
|
||||
}
|
||||
|
||||
export function validateStateStyleSyntax(temp: any, log: LogInfo[]) {
|
||||
export function validateStateStyleSyntax(temp: any, log: LogInfo[]): void {
|
||||
log.push({
|
||||
type: LogType.ERROR,
|
||||
message: `.stateStyles doesn't conform standard.`,
|
||||
|
||||
@@ -63,7 +63,7 @@ import {
|
||||
hasDecorator
|
||||
} from './utils';
|
||||
import { projectConfig } from '../main';
|
||||
const parser = require('../syntax_parser/dist/syntax_parser.js');
|
||||
const parser = require('../syntax_parser/dist/exclude_comment.js');
|
||||
|
||||
export interface ComponentCollection {
|
||||
entryComponent: string;
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
{
|
||||
const syntax_parser = require('./syntax_parser.js');
|
||||
}
|
||||
|
||||
start = blocks: block*
|
||||
{
|
||||
return syntax_parser.parse(blocks.join(''));
|
||||
}
|
||||
|
||||
block = comments/notComment
|
||||
|
||||
comments = comment:$("/*" (!"*/" .)* "*/") {
|
||||
let num = comment.split("\n").length-1;
|
||||
let result = '';
|
||||
while (num>0) {
|
||||
result += '\n';
|
||||
num -= 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
notComment = $((!comments .)+)
|
||||
@@ -13,14 +13,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
start = extendAttributes:extendAttribute+
|
||||
start = extendAttributes:whiteSpace extendAttribute+
|
||||
{
|
||||
return {location: location()};
|
||||
}
|
||||
|
||||
extendAttribute = whiteSpace '.' whiteSpace attribute item
|
||||
extendAttribute = (whiteSpace '.' whiteSpace attribute item)/(comment)
|
||||
attribute = attr_head attr_tail
|
||||
attr_head = $ [a-zA-Z_$]+
|
||||
attr_tail = $ [a-zA-Z0-9_$]*
|
||||
item = whiteSpace '(' [^()]* item* [^()]* ')' whiteSpace
|
||||
comment = "//" (![\r\n] .)* whiteSpace
|
||||
whiteSpace = [ \t\r\n]*
|
||||
|
||||
@@ -82,4 +82,4 @@ class FancyText extends View {
|
||||
}
|
||||
}
|
||||
loadDocument(new FancyText("1", undefined, {}));
|
||||
`
|
||||
`
|
||||
|
||||
@@ -249,4 +249,4 @@ module.exports = (env, argv) => {
|
||||
readAppResource(resources, appResourcePath);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user