Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import 外部 ts 文件报错 #4

Closed
l5oo00 opened this issue Oct 30, 2019 · 5 comments
Closed

import 外部 ts 文件报错 #4

l5oo00 opened this issue Oct 30, 2019 · 5 comments
Labels

Comments

@l5oo00
Copy link
Contributor

l5oo00 commented Oct 30, 2019

san 组件的 ts 文件里引用依赖的工具包 ts 文件, 报错 Error: Cannot find module 'xxx', 示例代码如下:

// app/components/demo.san.ts
import {Component} from 'san';
import {
    versionCompare
} from '../lib/utils';
export default class DemoComponent extends Component {
    static computed = {
        isOk() {
            return versionCompare('10.0', '9.0') >= 0;
        }
    }
    static template = `<div>
        {{ isOk ? 'san-ssr import bug.' : ''}}
    </div>`;
}


// app/lib/utils.ts
export function versionCompare(a, b) {
    return parseInt(a, 10) - parseInt(b, 10);
}

报错如下:

Error: Cannot find module '../lib/utils'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
    at Function.Module._load (internal/modules/cjs/loader.js:506:25)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at path (/projectRoot/node_modules/san-ssr/dist/loaders/common-js.js:35:24)
    at eval (eval at require (/projectRoot/node_modules/san-ssr/dist/loaders/common-js.js:29:24), <anonymous>:10:17)
    at CommonJS.require (/projectRoot/node_modules/san-ssr/dist/loaders/common-js.js:30:13)
    at ToJSCompiler.evalComponentClass (/projectRoot/node_modules/san-ssr/dist/compilers/to-js-compiler.js:62:25)
    at ToPHPCompiler.compileFromTS (/projectRoot/node_modules/san-ssr/dist/compilers/to-php-compiler.js:50:50)
    at ToPHPCompiler.compile (/projectRoot/node_modules/san-ssr/dist/compilers/to-php-compiler.js:39:25)
@l5oo00
Copy link
Contributor Author

l5oo00 commented Oct 30, 2019

将 utils 放到和 san.ts 平级的目录下, 就没有问题了

@l5oo00
Copy link
Contributor Author

l5oo00 commented Oct 30, 2019

还有个问题: 模板字符串的反引号(`)没有被转换为引号, 编译产出的 php 文件如下:

    class DemoComponent extends Component {
        public static $computed;
        public static $template = `<div>\\n        {{ isOk ? 'san-ssr import bug.' : ''}}\\n    </div>`;
    }

@harttle
Copy link
Member

harttle commented Oct 30, 2019

模板字符串语法是 ts2php 的问题,参见:searchfe/ts2php#66

@l5oo00
Copy link
Contributor Author

l5oo00 commented Oct 30, 2019

template 使用模板字符串并包含变量后, 会导致编译产出在 PHP 运行时报错, 和 @harttle 讨论后将所有 static 属性后置。

@harttle harttle closed this as completed in ce423a5 Nov 4, 2019
harttle pushed a commit that referenced this issue Nov 4, 2019
# [1.1.0](v1.0.5...v1.1.0) (2019-11-04)

### Bug Fixes

* '../' syntax in component files, close [#4](#4) ([ce423a5](ce423a5))
* ssr/csr difference respect to falsy attributes, closes [#5](#5) ([015c594](015c594))

### Features

* support ts2php modules config, close [#8](#8) ([c5a0c17](c5a0c17))
@harttle
Copy link
Member

harttle commented Nov 4, 2019

🎉 This issue has been resolved in version 1.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants