├── .browserlistrc ├── .eslintrc.js ├── .gitignore ├── LICENSE ├── README.md ├── __test__ ├── js │ ├── __snapshots__ │ │ └── index.spec.ts.snap │ ├── index.spec.ts │ └── transformation │ │ ├── __snapshots__ │ │ ├── api.spec.ts.snap │ │ └── structure.spec.ts.snap │ │ ├── api.spec.ts │ │ └── structure.spec.ts └── wxml │ ├── __snapshots__ │ ├── index.spec.ts.snap │ └── tags.spec.ts.snap │ ├── index.spec.ts │ └── tags.spec.ts ├── dist ├── @types │ ├── index.d.ts │ ├── language-js │ │ ├── generator.d.ts │ │ ├── index.d.ts │ │ ├── parser.d.ts │ │ └── transformation │ │ │ ├── api.d.ts │ │ │ ├── index.d.ts │ │ │ └── structure.d.ts │ ├── language-wxml │ │ ├── generator.d.ts │ │ ├── index.d.ts │ │ ├── parser.d.ts │ │ └── transformer.d.ts │ └── language-wxss │ │ ├── index.d.ts │ │ └── transformer.d.ts ├── es │ ├── index.js │ ├── index.js.map │ ├── language-js │ │ ├── generator.js │ │ ├── generator.js.map │ │ ├── index.js │ │ ├── index.js.map │ │ ├── parser.js │ │ ├── parser.js.map │ │ └── transformation │ │ │ ├── api.js │ │ │ ├── api.js.map │ │ │ ├── index.js │ │ │ ├── index.js.map │ │ │ ├── structure.js │ │ │ └── structure.js.map │ ├── language-wxml │ │ ├── generator.js │ │ ├── generator.js.map │ │ ├── index.js │ │ ├── index.js.map │ │ ├── parser.js │ │ ├── parser.js.map │ │ ├── transformer.js │ │ └── transformer.js.map │ └── language-wxss │ │ ├── index.js │ │ ├── index.js.map │ │ ├── transformer.js │ │ └── transformer.js.map ├── lib │ ├── index.js │ ├── index.js.map │ ├── language-js │ │ ├── generator.js │ │ ├── generator.js.map │ │ ├── index.js │ │ ├── index.js.map │ │ ├── parser.js │ │ ├── parser.js.map │ │ └── transformation │ │ │ ├── api.js │ │ │ ├── api.js.map │ │ │ ├── index.js │ │ │ ├── index.js.map │ │ │ ├── structure.js │ │ │ └── structure.js.map │ ├── language-wxml │ │ ├── generator.js │ │ ├── generator.js.map │ │ ├── index.js │ │ ├── index.js.map │ │ ├── parser.js │ │ ├── parser.js.map │ │ ├── transformer.js │ │ └── transformer.js.map │ └── language-wxss │ │ ├── index.js │ │ ├── index.js.map │ │ ├── transformer.js │ │ └── transformer.js.map ├── yu_gong.js └── yu_gong.js.map ├── jest.config.js ├── package-lock.json ├── package.json ├── rollup.config.ts ├── src ├── @types │ └── index.d.ts ├── index.ts ├── language-js │ ├── generator.ts │ ├── index.ts │ ├── parser.ts │ └── transformation │ │ ├── api.ts │ │ ├── index.ts │ │ └── structure.ts ├── language-vue │ └── generator.ts ├── language-wxml │ ├── generator.ts │ ├── index.ts │ ├── parser.ts │ └── transformer.ts └── language-wxss │ ├── index.ts │ └── transformer.ts └── tsconfig.json /.browserlistrc: -------------------------------------------------------------------------------- 1 | > 0.25% 2 | not dead 3 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | browser: true, 4 | es6: true, 5 | node: true 6 | }, 7 | extends: [ 8 | 'plugin:jest/recommended', 9 | 'standard' 10 | ], 11 | globals: { 12 | Atomics: 'readonly', 13 | SharedArrayBuffer: 'readonly' 14 | }, 15 | parser: '@typescript-eslint/parser', 16 | parserOptions: { 17 | ecmaVersion: 2018, 18 | sourceType: 'module' 19 | }, 20 | plugins: [ 21 | '@typescript-eslint', 22 | 'jest' 23 | ], 24 | rules: { 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 espkg 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mina2vue 2 | Convert native wxml, wxss eg. to .vue files 3 | 4 | ## Functions 5 | There are four main functions needed to successfully convert one page to vue. 6 | - `jsConverter` converts \*.js to vue-friendly js. 7 | - `wxmlConverter` converts \*.wxml to vue template syntax 8 | - `wxssConverter` converts \*.wxss to vue stylesheet (CSS) syntax 9 | - `vueGenerator` combines the three things above into a vue file's content. 10 | 11 | 12 | | fn | input | output | 13 | | -------------- | ------------ | ----------- | 14 | | jsConverter | sourceCode(string), options({ type: 'page' }) | script distCode(string) 15 | | wxmlConverter | sourceCode(string), options({}) | template distCode(string) 16 | | wxssConverter | sourceCode(string), options({}) | style distCode(string) 17 | | vueGenerator | template(wxmlConverter distCode), style(wxssConverter distCode), scripts(jsConverter distCode) | vue distCode(string) 18 | 19 | 20 | -------------------------------------------------------------------------------- /__test__/js/__snapshots__/index.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`should output js 1`] = `"const foo = \\"bar\\";"`; 4 | -------------------------------------------------------------------------------- /__test__/js/index.spec.ts: -------------------------------------------------------------------------------- 1 | import { jsConverter } from '../../src' 2 | 3 | it('should output js', () => { 4 | const input = 'const foo = "bar"' 5 | const output = jsConverter(input) 6 | 7 | expect(output).toMatchSnapshot() 8 | }) 9 | -------------------------------------------------------------------------------- /__test__/js/transformation/__snapshots__/api.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`convert setData to assignment 1`] = ` 4 | "export default { 5 | methods: { 6 | init() { 7 | this.foo = 'bar'; 8 | } 9 | 10 | } 11 | };" 12 | `; 13 | 14 | exports[`convert this.data.x to this.x 1`] = ` 15 | "export default { 16 | methods: { 17 | init() { 18 | const { 19 | foo 20 | } = this; 21 | const foo2 = this.foo2; 22 | } 23 | 24 | } 25 | };" 26 | `; 27 | 28 | exports[`execute setData callback function after convert 1`] = ` 29 | "export default { 30 | methods: { 31 | init() { 32 | this.foo = 'bar'; 33 | this.callback(); 34 | } 35 | 36 | } 37 | };" 38 | `; 39 | -------------------------------------------------------------------------------- /__test__/js/transformation/__snapshots__/structure.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`convert lifecycle methods to vue name properly 1`] = ` 4 | "export default { 5 | mixins: ['watch'], 6 | 7 | beforeMount() {}, 8 | 9 | destroyed() {}, 10 | 11 | mounted() {} 12 | 13 | };" 14 | `; 15 | 16 | exports[`convert page lifecycle methods to vue name properly 1`] = ` 17 | "export default { 18 | created() {}, 19 | 20 | mounted() {}, 21 | 22 | destroyed() {} 23 | 24 | };" 25 | `; 26 | 27 | exports[`convert property definition with Observer 1`] = ` 28 | "export default { 29 | props: { 30 | foo5: { 31 | type: Number, 32 | default: 0 33 | } 34 | }, 35 | watch: { 36 | foo5: (newVal, oldVal) => {// 属性值变化时执行 37 | } 38 | } 39 | };" 40 | `; 41 | 42 | exports[`convert property definition with Observer on reference types 1`] = ` 43 | "export default { 44 | props: { 45 | foo6: { 46 | type: Object, 47 | default: () => ({ 48 | bar: 1 49 | }) 50 | } 51 | }, 52 | watch: { 53 | foo6: { 54 | handler(newVal, oldVal) {// 属性值变化时执行 55 | }, 56 | 57 | deep: true 58 | } 59 | } 60 | };" 61 | `; 62 | 63 | exports[`convert property definition with default value 1`] = ` 64 | "export default { 65 | props: { 66 | foo2: { 67 | type: Number, 68 | default: 0 69 | } 70 | } 71 | };" 72 | `; 73 | 74 | exports[`convert property definition with default value on reference types 1`] = ` 75 | "export default { 76 | props: { 77 | foo3: { 78 | type: Object, 79 | default: () => ({ 80 | bar: 1 81 | }) 82 | }, 83 | foo4: { 84 | type: Array, 85 | default: () => [1, 2, 3] 86 | } 87 | } 88 | };" 89 | `; 90 | 91 | exports[`convert simple property definition 1`] = ` 92 | "export default { 93 | props: { 94 | foo1: Boolean 95 | } 96 | };" 97 | `; 98 | 99 | exports[`put other page methods & properties in vue methods property 1`] = ` 100 | "export default { 101 | _data: {}, 102 | methods: { 103 | initPage: () => {}, 104 | 105 | handleClick(e) {} 106 | 107 | } 108 | };" 109 | `; 110 | 111 | exports[`should avoid add additional watch property 1`] = ` 112 | "export default { 113 | props: { 114 | foo7: { 115 | type: Number, 116 | default: 0 117 | } 118 | }, 119 | watch: { 120 | foo7: (newVal, oldVal) => {// 属性值变化时执行 121 | } 122 | } 123 | };" 124 | `; 125 | 126 | exports[`should convert component data to vue format 1`] = ` 127 | "export default { 128 | data: () => ({}) 129 | };" 130 | `; 131 | 132 | exports[`should convert components' properties to vue props 1`] = ` 133 | "export default { 134 | props: {} 135 | };" 136 | `; 137 | 138 | exports[`should convert page data to vue format 1`] = ` 139 | "export default { 140 | data: () => ({}) 141 | };" 142 | `; 143 | 144 | exports[`should insert a watch property after existing properties 1`] = ` 145 | "export default { 146 | props: { 147 | foo8: { 148 | type: Number, 149 | default: 0 150 | } 151 | }, 152 | watch: { 153 | foo: () => {}, 154 | foo8: (newVal, oldVal) => {// 属性值变化时执行 155 | } 156 | } 157 | };" 158 | `; 159 | 160 | exports[`should output component to vue structure 1`] = `"export default {};"`; 161 | 162 | exports[`should output vue structure 1`] = `"export default {};"`; 163 | 164 | exports[`should put other methods & properties in vue methods properly 1`] = ` 165 | "export default { 166 | _data: {}, 167 | methods: { 168 | initPage: () => {}, 169 | 170 | handleClick(e) {} 171 | 172 | } 173 | };" 174 | `; 175 | -------------------------------------------------------------------------------- /__test__/js/transformation/api.spec.ts: -------------------------------------------------------------------------------- 1 | import { jsConverter } from '../../../src' 2 | 3 | it('convert setData to assignment', () => { 4 | const input = `Page({ 5 | init () { 6 | this.setData({ 7 | foo: 'bar' 8 | }) 9 | } 10 | })` 11 | const output = jsConverter(input) 12 | 13 | expect(output).toMatchSnapshot() 14 | }) 15 | 16 | it('execute setData callback function after convert', () => { 17 | const input = `Page({ 18 | init () { 19 | this.setData({ 20 | foo: 'bar' 21 | }, () => { 22 | this.callback() 23 | }) 24 | } 25 | })` 26 | const output = jsConverter(input) 27 | 28 | expect(output).toMatchSnapshot() 29 | }) 30 | 31 | it('convert this.data.x to this.x', () => { 32 | const input = `Page({ 33 | init () { 34 | const { foo } = this.data 35 | const foo2 = this.data.foo2 36 | } 37 | })` 38 | const output = jsConverter(input) 39 | 40 | expect(output).toMatchSnapshot() 41 | }) 42 | -------------------------------------------------------------------------------- /__test__/js/transformation/structure.spec.ts: -------------------------------------------------------------------------------- 1 | import { jsConverter } from '../../../src' 2 | 3 | it('should output vue structure', () => { 4 | const input = `Page({ 5 | })` 6 | const output = jsConverter(input) 7 | 8 | expect(output).toMatchSnapshot() 9 | }) 10 | 11 | it('should output component to vue structure', () => { 12 | const input = `Component({ 13 | })` 14 | const output = jsConverter(input, { 15 | type: 'component' 16 | }) 17 | 18 | expect(output).toMatchSnapshot() 19 | }) 20 | 21 | it('should convert components\' properties to vue props', () => { 22 | const input = `Component({ 23 | properties: {} 24 | })` 25 | const output = jsConverter(input, { 26 | type: 'component' 27 | }) 28 | 29 | expect(output).toMatchSnapshot() 30 | }) 31 | 32 | it('convert simple property definition', () => { 33 | const input = `Component({ 34 | properties: { 35 | foo1: Boolean 36 | } 37 | })` 38 | const output = jsConverter(input, { 39 | type: 'component' 40 | }) 41 | 42 | expect(output).toMatchSnapshot() 43 | }) 44 | 45 | it('convert property definition with default value', () => { 46 | const input = `Component({ 47 | properties: { 48 | foo2: { 49 | type: Number, 50 | value: 0 51 | } 52 | } 53 | })` 54 | const output = jsConverter(input, { 55 | type: 'component' 56 | }) 57 | 58 | expect(output).toMatchSnapshot() 59 | }) 60 | 61 | it('convert property definition with default value on reference types', () => { 62 | const input = `Component({ 63 | properties: { 64 | foo3: { 65 | type: Object, 66 | value: { 67 | bar: 1 68 | } 69 | }, 70 | foo4: { 71 | type: Array, 72 | value: [1, 2, 3] 73 | } 74 | } 75 | })` 76 | const output = jsConverter(input, { 77 | type: 'component' 78 | }) 79 | 80 | expect(output).toMatchSnapshot() 81 | }) 82 | 83 | it('convert property definition with Observer', () => { 84 | const input = `Component({ 85 | properties: { 86 | foo5: { 87 | type: Number, 88 | value: 0, 89 | observer: function (newVal, oldVal) { 90 | // 属性值变化时执行 91 | } 92 | } 93 | } 94 | })` 95 | const output = jsConverter(input, { 96 | type: 'component' 97 | }) 98 | 99 | expect(output).toMatchSnapshot() 100 | }) 101 | 102 | it('convert property definition with Observer on reference types', () => { 103 | const input = `Component({ 104 | properties: { 105 | foo6: { 106 | type: Object, 107 | value: { 108 | bar: 1 109 | }, 110 | observer: function (newVal, oldVal) { 111 | // 属性值变化时执行 112 | } 113 | } 114 | } 115 | })` 116 | const output = jsConverter(input, { 117 | type: 'component' 118 | }) 119 | 120 | expect(output).toMatchSnapshot() 121 | }) 122 | 123 | it('should avoid add additional watch property', () => { 124 | const input = `Component({ 125 | properties: { 126 | foo7: { 127 | type: Number, 128 | value: 0, 129 | observer: function (newVal, oldVal) { 130 | // 属性值变化时执行 131 | } 132 | } 133 | }, 134 | watch: {} 135 | })` 136 | const output = jsConverter(input, { 137 | type: 'component' 138 | }) 139 | 140 | expect(output).toMatchSnapshot() 141 | }) 142 | 143 | it('should insert a watch property after existing properties', () => { 144 | const input = `Component({ 145 | properties: { 146 | foo8: { 147 | type: Number, 148 | value: 0, 149 | observer: function (newVal, oldVal) { 150 | // 属性值变化时执行 151 | } 152 | } 153 | }, 154 | watch: { 155 | foo: () => {} 156 | } 157 | })` 158 | const output = jsConverter(input, { 159 | type: 'component' 160 | }) 161 | 162 | expect(output).toMatchSnapshot() 163 | }) 164 | 165 | it('should convert page data to vue format', () => { 166 | const input = `Page({ 167 | data: {} 168 | })` 169 | const output = jsConverter(input) 170 | 171 | expect(output).toMatchSnapshot() 172 | }) 173 | 174 | it('should convert component data to vue format', () => { 175 | const input = `Component({ 176 | data: {} 177 | })` 178 | const output = jsConverter(input, { 179 | type: 'component' 180 | }) 181 | 182 | expect(output).toMatchSnapshot() 183 | }) 184 | 185 | it('convert lifecycle methods to vue name properly', () => { 186 | const input = `Component({ 187 | behaviors: ['watch'], 188 | attached: () => {}, 189 | detached: function () {}, 190 | ready () {} 191 | })` 192 | const output = jsConverter(input, { 193 | type: 'component' 194 | }) 195 | 196 | expect(output).toMatchSnapshot() 197 | }) 198 | 199 | it('convert page lifecycle methods to vue name properly', () => { 200 | const input = `Page({ 201 | onLoad: () => {}, 202 | onReady: function () {}, 203 | onUnload () {} 204 | })` 205 | const output = jsConverter(input) 206 | 207 | expect(output).toMatchSnapshot() 208 | }) 209 | 210 | it('put other page methods & properties in vue methods property', () => { 211 | const input = `Page({ 212 | _data: {}, 213 | initPage: () => {}, 214 | handleClick (e) {} 215 | })` 216 | const output = jsConverter(input) 217 | 218 | expect(output).toMatchSnapshot() 219 | }) 220 | 221 | it('should put other methods & properties in vue methods properly', () => { 222 | const input = `Page({ 223 | _data: {}, 224 | initPage: () => {}, 225 | methods: {}, 226 | handleClick (e) {} 227 | })` 228 | const output = jsConverter(input) 229 | 230 | expect(output).toMatchSnapshot() 231 | }) 232 | -------------------------------------------------------------------------------- /__test__/wxml/__snapshots__/index.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`should convert less than sign correctly 1`] = `"
{{a<1?2:0}}{{chigua}}
"`; 4 | 5 | exports[`should print HTML 1`] = `""`; 6 | -------------------------------------------------------------------------------- /__test__/wxml/__snapshots__/tags.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`should convert to 1`] = `""`; 4 | 5 | exports[`should convert to
1`] = `"
"`; 6 | -------------------------------------------------------------------------------- /__test__/wxml/index.spec.ts: -------------------------------------------------------------------------------- 1 | import { wxmlConverter } from '../../src' 2 | 3 | it('should print HTML', async () => { 4 | const input = '' 5 | const output = await wxmlConverter(input) 6 | 7 | expect(output).toMatchSnapshot() 8 | }) 9 | 10 | it('should convert less than sign correctly', async () => { 11 | const input = '{{a<1?2:0}}{{chigua}}' 12 | const output = await wxmlConverter(input) 13 | 14 | expect(output).toMatchSnapshot() 15 | }) 16 | -------------------------------------------------------------------------------- /__test__/wxml/tags.spec.ts: -------------------------------------------------------------------------------- 1 | import { wxmlConverter } from '../../src' 2 | 3 | it('should convert to
', async () => { 4 | const input = '' 5 | const output = await wxmlConverter(input) 6 | 7 | expect(output).toMatchSnapshot() 8 | }) 9 | 10 | it('should convert to ', async () => { 11 | const input = '' 12 | const output = await wxmlConverter(input) 13 | 14 | expect(output).toMatchSnapshot() 15 | }) 16 | -------------------------------------------------------------------------------- /dist/@types/index.d.ts: -------------------------------------------------------------------------------- 1 | import wxmlConverter from './language-wxml'; 2 | import wxssConverter from './language-wxss'; 3 | import jsConverter from './language-js/index'; 4 | export { jsConverter, wxmlConverter, wxssConverter }; 5 | export default function (sourceCodes: string, options: any): void; 6 | -------------------------------------------------------------------------------- /dist/@types/language-js/generator.d.ts: -------------------------------------------------------------------------------- 1 | export default function (ast: babel.types.Node): string; 2 | -------------------------------------------------------------------------------- /dist/@types/language-js/index.d.ts: -------------------------------------------------------------------------------- 1 | export default function (sourceCode: string, options?: any): string; 2 | -------------------------------------------------------------------------------- /dist/@types/language-js/parser.d.ts: -------------------------------------------------------------------------------- 1 | export default function (sourceCode: string): babel.types.File; 2 | -------------------------------------------------------------------------------- /dist/@types/language-js/transformation/api.d.ts: -------------------------------------------------------------------------------- 1 | declare const _default: (api: any, options?: any) => import("@babel/core").PluginObj<{}>; 2 | export default _default; 3 | -------------------------------------------------------------------------------- /dist/@types/language-js/transformation/index.d.ts: -------------------------------------------------------------------------------- 1 | declare const _default: (ast: import("@babel/types").File, options: any) => import("@babel/types").File; 2 | export default _default; 3 | -------------------------------------------------------------------------------- /dist/@types/language-js/transformation/structure.d.ts: -------------------------------------------------------------------------------- 1 | declare const _default: (api: any, options?: any) => import("@babel/core").PluginObj<{}>; 2 | export default _default; 3 | -------------------------------------------------------------------------------- /dist/@types/language-wxml/generator.d.ts: -------------------------------------------------------------------------------- 1 | declare function HTMLGenerator(item: any, parent?: any, eachFn?: any): any; 2 | declare namespace HTMLGenerator { 3 | var configure: (userConfig: any) => void; 4 | } 5 | export default HTMLGenerator; 6 | -------------------------------------------------------------------------------- /dist/@types/language-wxml/index.d.ts: -------------------------------------------------------------------------------- 1 | export default function (sourceCode: string, options?: any): Promise; 2 | -------------------------------------------------------------------------------- /dist/@types/language-wxml/parser.d.ts: -------------------------------------------------------------------------------- 1 | export default function parse(sourceCode: string): Promise; 2 | -------------------------------------------------------------------------------- /dist/@types/language-wxml/transformer.d.ts: -------------------------------------------------------------------------------- 1 | export default function templateTransformer(ast: any, options: any): Promise; 2 | -------------------------------------------------------------------------------- /dist/@types/language-wxss/index.d.ts: -------------------------------------------------------------------------------- 1 | export default function (sourceCode: string, options?: any): string; 2 | -------------------------------------------------------------------------------- /dist/@types/language-wxss/transformer.d.ts: -------------------------------------------------------------------------------- 1 | export default function styleTransformer(sourceCode: string, options: any): string; 2 | -------------------------------------------------------------------------------- /dist/es/index.js: -------------------------------------------------------------------------------- 1 | import wxmlConverter from './language-wxml'; 2 | import wxssConverter from './language-wxss'; 3 | import jsConverter from './language-js/index'; 4 | export { jsConverter, wxmlConverter, wxssConverter }; 5 | export default function (sourceCodes, options) { 6 | } 7 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /dist/es/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,iBAAiB,CAAA;AAC3C,OAAO,aAAa,MAAM,iBAAiB,CAAA;AAC3C,OAAO,WAAW,MAAM,qBAAqB,CAAA;AAE7C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,CAAA;AAEpD,MAAM,CAAC,OAAO,WAAW,WAAoB,EAAE,OAAa;AAE5D,CAAC"} -------------------------------------------------------------------------------- /dist/es/language-js/generator.js: -------------------------------------------------------------------------------- 1 | import generator from '@babel/generator'; 2 | export default function (ast) { 3 | return generator(ast).code; 4 | } 5 | //# sourceMappingURL=generator.js.map -------------------------------------------------------------------------------- /dist/es/language-js/generator.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../src/language-js/generator.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,kBAAkB,CAAA;AAExC,MAAM,CAAC,OAAO,WAAW,GAAsB;IAC7C,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,CAAA;AAC5B,CAAC"} -------------------------------------------------------------------------------- /dist/es/language-js/index.js: -------------------------------------------------------------------------------- 1 | import parser from './parser'; 2 | import transformer from './transformation'; 3 | import generator from './generator'; 4 | export default function (sourceCode, options = { type: 'page' }) { 5 | const ast = parser(sourceCode); 6 | const distAst = transformer(ast, options); 7 | const distCode = generator(distAst); 8 | return distCode; 9 | } 10 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /dist/es/language-js/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/language-js/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,UAAU,CAAA;AAC7B,OAAO,WAAW,MAAM,kBAAkB,CAAA;AAC1C,OAAO,SAAS,MAAM,aAAa,CAAA;AAGnC,MAAM,CAAC,OAAO,WAAW,UAAmB,EAAE,UAAgB,EAAE,IAAI,EAAE,MAAM,EAAE;IAC5E,MAAM,GAAG,GAAsB,MAAM,CAAC,UAAU,CAAC,CAAA;IAEjD,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IAEzC,MAAM,QAAQ,GAAY,SAAS,CAAC,OAAO,CAAC,CAAA;IAE5C,OAAO,QAAQ,CAAA;AACjB,CAAC"} -------------------------------------------------------------------------------- /dist/es/language-js/parser.js: -------------------------------------------------------------------------------- 1 | import { parse } from '@babel/parser'; 2 | export default function (sourceCode) { 3 | return parse(sourceCode, { 4 | sourceType: 'module' 5 | }); 6 | } 7 | //# sourceMappingURL=parser.js.map -------------------------------------------------------------------------------- /dist/es/language-js/parser.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../../src/language-js/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAErC,MAAM,CAAC,OAAO,WAAW,UAAmB;IAC1C,OAAO,KAAK,CAAC,UAAU,EAAE;QACvB,UAAU,EAAE,QAAQ;KACrB,CAAC,CAAA;AACJ,CAAC"} -------------------------------------------------------------------------------- /dist/es/language-js/transformation/api.js: -------------------------------------------------------------------------------- 1 | import * as t from '@babel/types'; 2 | export default (api, options = {}) => { 3 | return { 4 | visitor: { 5 | CallExpression(path) { 6 | const { node } = path; 7 | const callee = node.callee; 8 | if (t.isThisExpression(callee.object) && callee.property.name === 'setData') { 9 | if (node.arguments.length === 2) { 10 | const afterFunction = node.arguments[1]; 11 | path.insertAfter(afterFunction.body.body); 12 | } 13 | const props = node.arguments[0].properties.reverse(); 14 | props.forEach((prop) => { 15 | path.insertAfter(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), prop.key), prop.value)); 16 | }); 17 | path.remove(); 18 | } 19 | }, 20 | ThisExpression(path) { 21 | const parentNode = path.parentPath.node; 22 | if (t.isMemberExpression(parentNode) && parentNode.property.name === 'data') { 23 | path.parentPath.replaceWith(t.thisExpression()); 24 | } 25 | } 26 | } 27 | }; 28 | }; 29 | //# sourceMappingURL=api.js.map -------------------------------------------------------------------------------- /dist/es/language-js/transformation/api.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"api.js","sourceRoot":"","sources":["../../../../src/language-js/transformation/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAA;AAEjC,eAAe,CAAC,GAAS,EAAE,UAAgB,EAAE,EAAoB,EAAE;IACjE,OAAO;QACL,OAAO,EAAE;YACP,cAAc,CAAE,IAAuC;gBACrD,MAAM,EAAE,IAAI,EAAE,GAAiC,IAAI,CAAA;gBACnD,MAAM,MAAM,GAAG,IAAI,CAAC,MAA4B,CAAA;gBAGhD,IAAI,CAAC,CAAC,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,KAAK,SAAS,EAAE;oBAE3E,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;wBAC/B,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAyB,CAAA;wBAC/D,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;qBAC1C;oBAED,MAAM,KAAK,GAAK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAwB,CAAC,UAAiC,CAAC,OAAO,EAAE,CAAA;oBACpG,KAAK,CAAC,OAAO,CAAC,CAAC,IAAuB,EAAE,EAAE;wBACxC,IAAI,CAAC,WAAW,CACd,CAAC,CAAC,oBAAoB,CAAC,GAAG,EAAE,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,cAAc,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,EAAG,IAAI,CAAC,KAAsB,CAAC,CAC5G,CAAA;oBACH,CAAC,CAAC,CAAA;oBAEF,IAAI,CAAC,MAAM,EAAE,CAAA;iBACd;YACH,CAAC;YACD,cAAc,CAAE,IAAI;gBAElB,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAA;gBACvC,IAAI,CAAC,CAAC,kBAAkB,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,IAAI,KAAK,MAAM,EAAE;oBAC3E,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,cAAc,EAAE,CAAC,CAAA;iBAChD;YACH,CAAC;SACF;KACF,CAAA;AACH,CAAC,CAAA"} -------------------------------------------------------------------------------- /dist/es/language-js/transformation/index.js: -------------------------------------------------------------------------------- 1 | import traverse from '@babel/traverse'; 2 | import structureTransformer from './structure'; 3 | import apiTransformer from './api'; 4 | const codeMods = [structureTransformer, apiTransformer]; 5 | export default (ast, options) => { 6 | const distAst = codeMods.reduce((prev, curr) => { 7 | traverse(prev, curr(null, options).visitor); 8 | return prev; 9 | }, ast); 10 | return distAst; 11 | }; 12 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /dist/es/language-js/transformation/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/language-js/transformation/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,iBAAiB,CAAA;AACtC,OAAO,oBAAoB,MAAM,aAAa,CAAA;AAC9C,OAAO,cAAc,MAAM,OAAO,CAAA;AAElC,MAAM,QAAQ,GAAqB,CAAC,oBAAoB,EAAE,cAAc,CAAC,CAAA;AAEzE,eAAe,CAAC,GAAsB,EAAE,OAAa,EAAqB,EAAE;IAE1E,MAAM,OAAO,GAAS,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAQ,EAAE;QACzD,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,CAAA;QAC3C,OAAO,IAAI,CAAA;IACb,CAAC,EAAE,GAAG,CAAC,CAAA;IACP,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"} -------------------------------------------------------------------------------- /dist/es/language-js/transformation/structure.js: -------------------------------------------------------------------------------- 1 | import * as t from '@babel/types'; 2 | function handleProperty(path, rootPath) { 3 | const { node } = path; 4 | if (t.isObjectExpression(node.value)) { 5 | const propsPath = path.get('value.properties'); 6 | const propTypePath = propsPath.filter((propPath) => t.isNodesEquivalent(propPath.node.key, t.identifier('type')))[0]; 7 | const typeNode = propTypePath.node.value; 8 | let watchPropNode = t.objectProperty(node.key, t.nullLiteral()); 9 | propsPath.forEach((propPath) => { 10 | const propNode = propPath.node; 11 | const keyName = propNode.key.name; 12 | const watchPropIndex = rootPath.findIndex((propPath) => t.isNodesEquivalent(propPath.node.key, t.identifier('watch'))); 13 | switch (keyName) { 14 | case 'value': 15 | if (t.isNodesEquivalent(typeNode, t.identifier('Object'))) { 16 | propPath.replaceWith(t.objectProperty(t.identifier('default'), t.arrowFunctionExpression([], propNode.value))); 17 | } 18 | else if (t.isNodesEquivalent(typeNode, t.identifier('Array'))) { 19 | propPath.replaceWith(t.objectProperty(t.identifier('default'), t.arrowFunctionExpression([], propNode.value))); 20 | } 21 | else { 22 | propPath.replaceWith(t.objectProperty(t.identifier('default'), propNode.value)); 23 | } 24 | break; 25 | case 'observer': 26 | if (t.isNodesEquivalent(typeNode, t.identifier('Object')) || t.isNodesEquivalent(typeNode, t.identifier('Array'))) { 27 | watchPropNode = t.objectProperty(node.key, t.objectExpression([ 28 | t.objectMethod('method', t.identifier('handler'), propNode.value.params, propNode.value.body), 29 | t.objectProperty(t.identifier('deep'), t.booleanLiteral(true)) 30 | ])); 31 | } 32 | else { 33 | watchPropNode = t.objectProperty(node.key, t.arrowFunctionExpression(propNode.value.params, propNode.value.body)); 34 | } 35 | if (watchPropIndex === -1) { 36 | rootPath[rootPath.length - 1].insertAfter(t.objectProperty(t.identifier('watch'), t.objectExpression([watchPropNode]))); 37 | } 38 | else { 39 | const propsPath = rootPath[watchPropIndex].get('value.properties'); 40 | if (propsPath.length) { 41 | propsPath[propsPath.length - 1].insertAfter(watchPropNode); 42 | } 43 | else { 44 | rootPath[watchPropIndex].replaceWith(t.objectProperty(t.identifier('watch'), t.objectExpression([watchPropNode]))); 45 | } 46 | } 47 | propPath.remove(); 48 | break; 49 | } 50 | }); 51 | } 52 | } 53 | function handleProperties(path, rootPath) { 54 | const { node } = path; 55 | const propsPath = path.get('value.properties'); 56 | propsPath.forEach((propPath) => { 57 | handleProperty(propPath, rootPath); 58 | }); 59 | path.replaceWith(t.objectProperty(t.identifier('props'), node.value)); 60 | } 61 | function handleData(path) { 62 | const { node } = path; 63 | path.replaceWith(t.objectProperty(t.identifier('data'), t.arrowFunctionExpression([], node.value))); 64 | } 65 | function handleLifeCycles(path) { 66 | const { node } = path; 67 | const keyName = node.key.name; 68 | const keyNameMap = { 69 | ready: 'mounted', 70 | attached: 'beforeMount', 71 | detached: 'destroyed', 72 | behaviors: 'mixins', 73 | onLoad: 'created', 74 | onReady: 'mounted', 75 | onUnload: 'destroyed' 76 | }; 77 | if (t.isObjectMethod(node)) { 78 | path.replaceWith(t.objectMethod('method', t.identifier(keyNameMap[keyName]), node.params, node.body)); 79 | } 80 | else if (t.isObjectProperty(node)) { 81 | const { value } = node; 82 | if (t.isFunctionExpression(value) || t.isArrowFunctionExpression(value)) { 83 | path.replaceWith(t.objectMethod('method', t.identifier(keyNameMap[keyName]), value.params, value.body)); 84 | } 85 | else { 86 | path.replaceWith(t.objectProperty(t.identifier(keyNameMap[keyName]), value)); 87 | } 88 | } 89 | } 90 | function handleOtherProperties(path, rootPath) { 91 | const { node } = path; 92 | const rootPropsPath = rootPath.get('arguments.0.properties'); 93 | const methodsPropIndex = rootPropsPath.findIndex((propPath) => propPath.node && t.isNodesEquivalent(propPath.node.key, t.identifier('methods'))); 94 | if (t.isObjectMethod(node) || (t.isArrowFunctionExpression(node.value) || t.isFunctionExpression(node.value))) { 95 | if (methodsPropIndex === -1) { 96 | rootPropsPath[rootPropsPath.length - 1].insertAfter(t.objectProperty(t.identifier('methods'), t.objectExpression([node]))); 97 | } 98 | else { 99 | const propsPath = rootPropsPath[methodsPropIndex].get('value.properties'); 100 | if (propsPath.length) { 101 | propsPath[propsPath.length - 1].insertAfter(node); 102 | } 103 | else { 104 | rootPropsPath[methodsPropIndex].replaceWith(t.objectProperty(t.identifier('methods'), t.objectExpression([node]))); 105 | } 106 | } 107 | path.remove(); 108 | } 109 | } 110 | export default (api, options = {}) => { 111 | return { 112 | visitor: { 113 | CallExpression(path) { 114 | const { node } = path; 115 | const { callee } = node; 116 | const rootName = options.rootName || (options.type === 'page' ? 'Page' : 'Component'); 117 | if (options.type === 'page') { 118 | if (callee.name === rootName) { 119 | const pageArgNode = node.arguments[0]; 120 | const propsPath = path.get('arguments.0.properties'); 121 | propsPath.forEach((propPath) => { 122 | const { name } = propPath.node.key; 123 | switch (name) { 124 | case 'data': 125 | handleData(propPath); 126 | break; 127 | case 'onLoad': 128 | case 'onReady': 129 | case 'onUnload': 130 | handleLifeCycles(propPath); 131 | break; 132 | default: 133 | handleOtherProperties(propPath, path); 134 | } 135 | }); 136 | path.parentPath.replaceWith(t.exportDefaultDeclaration(pageArgNode)); 137 | } 138 | } 139 | else if (options.type === 'component') { 140 | if (callee.name === rootName) { 141 | const componentArgNode = node.arguments[0]; 142 | const propsPath = path.get('arguments.0.properties'); 143 | propsPath.forEach((propPath) => { 144 | const { name } = propPath.node.key; 145 | switch (name) { 146 | case 'properties': 147 | handleProperties(propPath, propsPath); 148 | break; 149 | case 'data': 150 | handleData(propPath); 151 | break; 152 | case 'attached': 153 | case 'detached': 154 | case 'behaviors': 155 | case 'ready': 156 | handleLifeCycles(propPath); 157 | break; 158 | default: 159 | handleOtherProperties(propPath, path); 160 | } 161 | }); 162 | path.parentPath.replaceWith(t.exportDefaultDeclaration(componentArgNode)); 163 | } 164 | } 165 | } 166 | } 167 | }; 168 | }; 169 | //# sourceMappingURL=structure.js.map -------------------------------------------------------------------------------- /dist/es/language-js/transformation/structure.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"structure.js","sourceRoot":"","sources":["../../../../src/language-js/transformation/structure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAA;AAEjC,SAAS,cAAc,CAAE,IAAuC,EAAE,QAA6C;IAC7G,MAAM,EAAE,IAAI,EAAE,GAAiC,IAAI,CAAA;IAEnD,IAAI,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;QACpC,MAAM,SAAS,GAAI,IAAI,CAAC,GAAG,CAA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AAU,CAAC,WAAW,CACzB,CAAC,CAAC,wBAAwB,CAAC,WAAW,CAAC,CACxC,CAAA;qBACF;iBACF;qBAAM,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW,EAAE;oBACvC,IAAK,MAAkC,CAAC,IAAI,KAAK,QAAQ,EAAE;wBAEzD,MAAM,gBAAgB,GAAyB,IAAI,CAAC,SAAS,CAAC,CAAC,CAAwB,CAAA;wBACvF,MAAM,SAAS,GAAI,IAAI,CAAC,GAAG,CAAC,wBAAwB,CAAwC,CAAA;wBAG5F,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;4BAC7B,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAA;4BAElC,QAAQ,IAAI,EAAE;gCACZ,KAAK,YAAY;oCACf,gBAAgB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;oCACrC,MAAK;gCACP,KAAK,MAAM;oCACT,UAAU,CAAC,QAAQ,CAAC,CAAA;oCACpB,MAAK;gCAKP,KAAK,UAAU,CAAC;gCAChB,KAAK,UAAU,CAAC;gCAChB,KAAK,WAAW,CAAC;gCACjB,KAAK,OAAO;oCACV,gBAAgB,CAAC,QAAQ,CAAC,CAAA;oCAC1B,MAAK;gCACP;oCACE,qBAAqB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;6BACxC;wBACH,CAAC,CAAC,CAAA;wBAEF,IAAI,CAAC,UAAU,CAAC,WAAW,CACzB,CAAC,CAAC,wBAAwB,CAAC,gBAAgB,CAAC,CAC7C,CAAA;qBACF;iBACF;YACH,CAAC;SACF;KACF,CAAA;AACH,CAAC,CAAA"} -------------------------------------------------------------------------------- /dist/es/language-wxml/generator.js: -------------------------------------------------------------------------------- 1 | var emptyTags = { 2 | area: 1, 3 | base: 1, 4 | basefont: 1, 5 | br: 1, 6 | col: 1, 7 | frame: 1, 8 | hr: 1, 9 | img: 1, 10 | input: 1, 11 | isindex: 1, 12 | link: 1, 13 | meta: 1, 14 | param: 1, 15 | embed: 1, 16 | '?xml': 1 17 | }; 18 | var ampRe = /&/g; 19 | var ltRe = //g; 21 | var quotRe = /"/g; 22 | var eqRe = /=/g; 23 | var config = { 24 | disableAttribEscape: false 25 | }; 26 | function escapeAttrib(s) { 27 | if (config.disableAttribEscape === true) { 28 | return s.toString(); 29 | } 30 | if (s == null) { 31 | return ''; 32 | } 33 | if (s.toString && typeof s.toString === 'function') { 34 | return s.toString().replace(ampRe, '&').replace(ltRe, '<').replace(gtRe, '>') 35 | .replace(quotRe, '"').replace(eqRe, '='); 36 | } 37 | else { 38 | return ''; 39 | } 40 | } 41 | export default function HTMLGenerator(item, parent, eachFn) { 42 | if (Array.isArray(item)) { 43 | return item.map(function (subitem) { 44 | return HTMLGenerator(subitem, parent, eachFn); 45 | }).join(''); 46 | } 47 | var orig = item; 48 | if (eachFn) { 49 | item = eachFn(item, parent); 50 | } 51 | if (typeof item !== 'undefined' && typeof item.type !== 'undefined') { 52 | switch (item.type) { 53 | case 'text': 54 | return item.data; 55 | case 'directive': 56 | return '<' + item.data + '>'; 57 | case 'comment': 58 | return ''; 59 | case 'style': 60 | case 'script': 61 | case 'tag': 62 | var result = '<' + item.name; 63 | if (item.attribs && Object.keys(item.attribs).length > 0) { 64 | result += ' ' + Object.keys(item.attribs).map(function (key) { 65 | return key + '="' + escapeAttrib(item.attribs[key]) + '"'; 66 | }).join(' '); 67 | } 68 | if (item.children) { 69 | if (!orig.render) { 70 | orig = parent; 71 | } 72 | result += '>' + HTMLGenerator(item.children, orig, eachFn) + (emptyTags[item.name] ? '' : ''); 73 | } 74 | else { 75 | if (emptyTags[item.name]) { 76 | result += '>'; 77 | } 78 | else { 79 | result += '>'; 80 | } 81 | } 82 | return result; 83 | case 'cdata': 84 | return ''; 85 | } 86 | } 87 | return item; 88 | } 89 | HTMLGenerator.configure = function (userConfig) { 90 | if (userConfig !== undefined) { 91 | for (const k in config) { 92 | if (userConfig[k] !== undefined) { 93 | config[k] = userConfig[k]; 94 | } 95 | } 96 | } 97 | }; 98 | //# sourceMappingURL=generator.js.map -------------------------------------------------------------------------------- /dist/es/language-wxml/generator.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../src/language-wxml/generator.ts"],"names":[],"mappings":"AAAA,IAAI,SAAS,GAAS;IACpB,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,QAAQ,EAAE,CAAC;IACX,EAAE,EAAE,CAAC;IACL,GAAG,EAAE,CAAC;IACN,KAAK,EAAE,CAAC;IACR,EAAE,EAAE,CAAC;IACL,GAAG,EAAE,CAAC;IACN,KAAK,EAAE,CAAC;IACR,OAAO,EAAE,CAAC;IACV,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;CACV,CAAA;AAED,IAAI,KAAK,GAAG,IAAI,CAAA;AAEhB,IAAI,IAAI,GAAG,IAAI,CAAA;AACf,IAAI,IAAI,GAAG,IAAI,CAAA;AACf,IAAI,MAAM,GAAG,IAAI,CAAA;AACjB,IAAI,IAAI,GAAG,IAAI,CAAA;AAEf,IAAI,MAAM,GAAS;IACjB,mBAAmB,EAAE,KAAK;CAC3B,CAAA;AAED,SAAS,YAAY,CAAE,CAAO;IAC5B,IAAI,MAAM,CAAC,mBAAmB,KAAK,IAAI,EAAE;QAAE,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAA;KAAE;IAGhE,IAAI,CAAC,IAAI,IAAI,EAAE;QAAE,OAAO,EAAE,CAAA;KAAE;IAC5B,IAAI,CAAC,CAAC,QAAQ,IAAI,OAAO,CAAC,CAAC,QAAQ,KAAK,UAAU,EAAE;QAElD,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,C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,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,UAAU,GAAG;wBACzD,OAAO,GAAG,GAAG,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAA;oBAC3D,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;iBACb;gBACD,IAAI,IAAI,CAAC,QAAQ,EAAE;oBAGjB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;wBAChB,IAAI,GAAG,MAAM,CAAA;qBACd;oBACD,MAAM,IAAI,GAAG,GAAG,aAAa,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,CAAA;iBAClH;qBAAM;oBACL,IAAI,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;wBACxB,MAAM,IAAI,GAAG,CAAA;qBACd;yBAAM;wBACL,MAAM,IAAI,KAAK,GAAG,IAAI,CAAC,IAAI,GAAG,GAAG,CAAA;qBAClC;iBACF;gBACD,OAAO,MAAM,CAAA;YACf,KAAK,OAAO;gBACV,OAAO,UAAU,GAAG,IAAI,CAAC,IAAI,GAAG,KAAK,CAAA;SACxC;KACF;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,aAAa,CAAC,SAAS,GAAG,UAAU,UAAgB;IAClD,IAAI,UAAU,KAAK,SAAS,EAAE;QAC5B,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE;YACtB,IAAI,UAAU,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE;gBAC/B,MAAM,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;aAC1B;SACF;KACF;AACH,CAAC,CAAA"} -------------------------------------------------------------------------------- /dist/es/language-wxml/index.js: -------------------------------------------------------------------------------- 1 | import parser from './parser'; 2 | import transformer from './transformer'; 3 | import generator from './generator'; 4 | export default async function (sourceCode, options = {}) { 5 | const ast = await parser(sourceCode); 6 | const distAst = await transformer(ast, options); 7 | generator.configure({ 8 | disableAttribEscape: true 9 | }); 10 | const distCode = generator(distAst); 11 | return distCode; 12 | } 13 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /dist/es/language-wxml/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/language-wxml/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,UAAU,CAAA;AAC7B,OAAO,WAAW,MAAM,eAAe,CAAA;AACvC,OAAO,SAAS,MAAM,aAAa,CAAA;AAGnC,MAAM,CAAC,OAAO,CAAC,KAAK,WAAW,UAAmB,EAAE,UAAgB,EAAG;IACrE,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,CAAA;IAEpC,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IAE/C,SAAS,CAAC,SAAS,CAAC;QAClB,mBAAmB,EAAE,IAAI;KAC1B,CAAC,CAAA;IACF,MAAM,QAAQ,GAAY,SAAS,CAAC,OAAO,CAAC,CAAA;IAE5C,OAAO,QAAQ,CAAA;AACjB,CAAC"} -------------------------------------------------------------------------------- /dist/es/language-wxml/parser.js: -------------------------------------------------------------------------------- 1 | import { DomHandler, Parser } from 'htmlparser2'; 2 | export default function parse(sourceCode) { 3 | return new Promise((resolve, reject) => { 4 | const handler = new DomHandler((err, dom) => { 5 | if (err) { 6 | reject(err); 7 | } 8 | resolve(dom); 9 | }); 10 | const parser = new Parser(handler, { 11 | xmlMode: true, 12 | lowerCaseTags: false, 13 | recognizeSelfClosing: true 14 | }); 15 | parser.write(sourceCode); 16 | parser.end(); 17 | }); 18 | } 19 | //# sourceMappingURL=parser.js.map -------------------------------------------------------------------------------- /dist/es/language-wxml/parser.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../../src/language-wxml/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEhD,MAAM,CAAC,OAAO,UAAU,KAAK,CAAE,UAAmB;IAChD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YAC1C,IAAI,GAAG,EAAE;gBACP,MAAM,CAAC,GAAG,CAAC,CAAA;aACZ;YAED,OAAO,CAAC,GAAG,CAAC,CAAA;QACd,CAAC,CAAC,CAAA;QAEF,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,OAAO,EAAE;YACjC,OAAO,EAAE,IAAI;YACb,aAAa,EAAE,KAAK;YACpB,oBAAoB,EAAE,IAAI;SAC3B,CAAC,CAAA;QACF,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;QACxB,MAAM,CAAC,GAAG,EAAE,CAAA;IACd,CAAC,CAAC,CAAA;AACJ,CAAC"} -------------------------------------------------------------------------------- /dist/es/language-wxml/transformer.js: -------------------------------------------------------------------------------- 1 | function dynamicValue(value) { 2 | if (!value) 3 | return []; 4 | return value.match(/{{(.*?)}}/g); 5 | } 6 | function tagTransformer(node) { 7 | switch (node.name) { 8 | case 'view': 9 | node.name = 'div'; 10 | break; 11 | case 'text': 12 | node.name = 'span'; 13 | break; 14 | case 'block': 15 | node.name = 'template'; 16 | break; 17 | case 'image': 18 | node.name = 'img'; 19 | break; 20 | case 'mf-page': 21 | node.name = 'div'; 22 | break; 23 | default: 24 | } 25 | } 26 | function handleClassAttribute(value, node) { 27 | const regValue = dynamicValue(value); 28 | if (regValue && regValue.length) { 29 | const dynamicClassValue = regValue.map((item) => item.replace(/{{(.*?)}}/, '$1')); 30 | node.attribs[':class'] = `[${dynamicClassValue}]`; 31 | const restValue = regValue.reduce((accu, curr) => { 32 | return accu.replace(curr, ''); 33 | }, value); 34 | node.attribs.class = restValue.trim(); 35 | } 36 | } 37 | function handleStyleAttribute(value, node) { 38 | const styleList = value.split(';'); 39 | const normalStyle = []; 40 | const dynamicStyle = {}; 41 | let finalDynamicStyle = ''; 42 | styleList.forEach((style) => { 43 | const regValue = dynamicValue(style); 44 | if (regValue && regValue.length) { 45 | let [property, styleValue] = style.split(':'); 46 | let finalStyleValue = ''; 47 | property = property.replace(/-(\w)/g, (all, letter) => letter.toUpperCase()).trim(); 48 | const firstSplit = styleValue.split('{{'); 49 | let secondSplit = []; 50 | firstSplit.forEach((item) => { 51 | secondSplit = secondSplit.concat(item.split('}}')); 52 | }); 53 | secondSplit.forEach((part, index) => { 54 | if (!part) 55 | return; 56 | if (finalStyleValue.length) 57 | finalStyleValue += (index > 0 && '+') || ''; 58 | finalStyleValue += (index % 2 ? part : JSON.stringify(part.trim())); 59 | }); 60 | const transferFinalStyleValue = finalStyleValue.replace(/([\d]+)rpx/g, (m, $1) => { 61 | const newPx = $1.replace(/(^:)|(:$)/g, ''); 62 | return `${newPx * 0.5}px`; 63 | }); 64 | dynamicStyle[property] = transferFinalStyleValue; 65 | } 66 | else { 67 | const css = style.trim(); 68 | const transferFinalStyleValue = css.replace(/([\d]+)rpx/g, (m, $1) => { 69 | const newPx = $1.replace(/(^:)|(:$)/g, ''); 70 | return `${newPx * 0.5}px`; 71 | }); 72 | normalStyle.push(transferFinalStyleValue); 73 | } 74 | }); 75 | node.attribs.style = normalStyle.join(';'); 76 | if (Object.keys(dynamicStyle).length) { 77 | finalDynamicStyle = '{ '; 78 | Object.keys(dynamicStyle).forEach((property) => { 79 | const value = dynamicStyle[property]; 80 | finalDynamicStyle += property; 81 | finalDynamicStyle += ': '; 82 | finalDynamicStyle += value.replace(/"/g, "'"); 83 | finalDynamicStyle += ';'; 84 | }); 85 | finalDynamicStyle += ' }'; 86 | node.attribs[':style'] = finalDynamicStyle; 87 | } 88 | } 89 | function handleBindAttribute(value, attribute, node) { 90 | let eventName = ''; 91 | if (attribute.indexOf(':') !== -1) { 92 | eventName = attribute.split(':')[1]; 93 | } 94 | else { 95 | eventName = attribute.substr(4); 96 | } 97 | if (eventName === 'tap') 98 | eventName = 'click'; 99 | node.attribs[`@${eventName}`] = `${value}($event)`; 100 | delete node.attribs[attribute]; 101 | } 102 | function handleCatchAttribute(value, attribute, node) { 103 | let eventName = ''; 104 | if (attribute.indexOf(':') !== -1) { 105 | eventName = attribute.split(':')[1]; 106 | } 107 | else { 108 | eventName = attribute.substr(5); 109 | } 110 | if (eventName === 'tap') 111 | eventName = 'click'; 112 | node.attribs[`@${eventName}.stop`] = value; 113 | delete node.attribs[attribute]; 114 | } 115 | function handleWXAttribute(value, attribute, node) { 116 | const attrName = attribute.split(':')[1]; 117 | switch (attrName) { 118 | case 'if': 119 | node.attribs['v-if'] = value.replace(/{{(.*?)}}/, '$1').trim(); 120 | delete node.attribs[attribute]; 121 | break; 122 | case 'else': 123 | node.attribs['v-else'] = ''; 124 | delete node.attribs[attribute]; 125 | break; 126 | case 'elif': 127 | node.attribs['v-else-if'] = value.replace(/{{(.*?)}}/, '$1').trim(); 128 | delete node.attribs[attribute]; 129 | break; 130 | case 'key': 131 | node.attribs[':key'] = value.replace(/{{(.*?)}}/, '$1').trim(); 132 | delete node.attribs[attribute]; 133 | break; 134 | case 'for': 135 | const forItem = node.attribs['wx:for-item']; 136 | const forIndex = node.attribs['wx:for-index']; 137 | const forContent = value.replace(/{{(.*?)}}/, '$1').trim(); 138 | node.attribs['v-for'] = `(${forItem || 'item'}, ${forIndex || 'index'}) in ${forContent}`; 139 | delete node.attribs['wx:for-item']; 140 | delete node.attribs['wx:for-index']; 141 | delete node.attribs[attribute]; 142 | break; 143 | } 144 | } 145 | function handleElseAttribute(value, attribute, node) { 146 | if (dynamicValue(value) && dynamicValue(value).length) { 147 | node.attribs[`:${attribute}`] = value.replace(/{{(.*?)}}/, '$1').trim(); 148 | delete node.attribs[attribute]; 149 | } 150 | } 151 | function attributeTransformer(node) { 152 | Object.keys(node.attribs).forEach((attribute) => { 153 | const value = node.attribs[attribute]; 154 | if (attribute === 'class') { 155 | handleClassAttribute(value, node); 156 | } 157 | else if (attribute === 'style') { 158 | handleStyleAttribute(value, node); 159 | } 160 | else if (attribute.match(/^bind/)) { 161 | handleBindAttribute(value, attribute, node); 162 | } 163 | else if (attribute.match(/^catch/)) { 164 | handleCatchAttribute(value, attribute, node); 165 | } 166 | else if (attribute.match(/^wx:/)) { 167 | handleWXAttribute(value, attribute, node); 168 | } 169 | else if (attribute === 'mfConfig') { 170 | delete node.attribs[attribute]; 171 | } 172 | else { 173 | handleElseAttribute(value, attribute, node); 174 | } 175 | }); 176 | } 177 | export default async function templateTransformer(ast, options) { 178 | for (let i = 0; i < ast.length; i++) { 179 | const node = ast[i]; 180 | switch (node.type) { 181 | case 'tag': 182 | tagTransformer(node); 183 | attributeTransformer(node); 184 | break; 185 | default: 186 | } 187 | if (node.children) { 188 | templateTransformer(node.children, options); 189 | } 190 | } 191 | return ast; 192 | } 193 | //# sourceMappingURL=transformer.js.map -------------------------------------------------------------------------------- /dist/es/language-wxml/transformer.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"transformer.js","sourceRoot":"","sources":["../../../src/language-wxml/transformer.ts"],"names":[],"mappings":"AAAA,SAAS,YAAY,CAAE,KAAW;IAChC,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAA;IACrB,OAAO,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;AAClC,CAAC;AAED,SAAS,cAAc,CAAE,IAAU;IACjC,QAAQ,IAAI,CAAC,IAAI,EAAE;QACjB,KAAK,MAAM;YACT,IAAI,CAAC,IAAI,GAAG,KAAK,CAAA;YACjB,MAAK;QAEP,KAAK,MAAM;YACT,IAAI,CAAC,IAAI,GAAG,MAAM,CAAA;YAClB,MAAK;QAEP,KAAK,OAA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,CAAC;AAED,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,mBAAmB,CAAE,GAAS,EAAE,OAAa;IACzE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACnC,MAAM,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;QAEnB,QAAQ,IAAI,CAAC,IAAI,EAAE;YACjB,KAAK,KAAK;gBACR,cAAc,CAAC,IAAI,CAAC,CAAA;gBACpB,oBAAoB,CAAC,IAAI,CAAC,CAAA;gBAC1B,MAAK;YAEP,QAAQ;SACT;QAED,IAAI,IAAI,CAAC,QAAQ,EAAE;YACjB,mBAAmB,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;SAC5C;KACF;IAED,OAAO,GAAG,CAAA;AACZ,CAAC"} -------------------------------------------------------------------------------- /dist/es/language-wxss/index.js: -------------------------------------------------------------------------------- 1 | import transformer from './transformer'; 2 | export default function (sourceCode, options = { type: 'page' }) { 3 | const distCode = transformer(sourceCode, options); 4 | return distCode; 5 | } 6 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /dist/es/language-wxss/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/language-wxss/index.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,eAAe,CAAA;AAGvC,MAAM,CAAC,OAAO,WAAW,UAAmB,EAAE,UAAgB,EAAE,IAAI,EAAE,MAAM,EAAE;IAC5E,MAAM,QAAQ,GAAG,WAAW,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;IAEjD,OAAO,QAAQ,CAAA;AACjB,CAAC"} -------------------------------------------------------------------------------- /dist/es/language-wxss/transformer.js: -------------------------------------------------------------------------------- 1 | export default function styleTransformer(sourceCode, options) { 2 | const css = sourceCode.replace(/([\d]+)rpx/g, (m, $1) => { 3 | const newPx = $1.replace(/(^:)|(:$)/g, ''); 4 | return `${newPx * 0.5}px`; 5 | }); 6 | return css; 7 | } 8 | //# sourceMappingURL=transformer.js.map -------------------------------------------------------------------------------- /dist/es/language-wxss/transformer.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"transformer.js","sourceRoot":"","sources":["../../../src/language-wxss/transformer.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAE,UAAmB,EAAE,OAAa;IAC1E,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE;QACtD,MAAM,KAAK,GAAG,EAAE,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAA;QAC1C,OAAO,GAAG,KAAK,GAAG,GAAG,IAAI,CAAA;IAC3B,CAAC,CAAC,CAAA;IACF,OAAO,GAAG,CAAA;AACZ,CAAC"} -------------------------------------------------------------------------------- /dist/lib/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const language_wxml_1 = __importDefault(require("./language-wxml")); 7 | exports.wxmlConverter = language_wxml_1.default; 8 | const language_wxss_1 = __importDefault(require("./language-wxss")); 9 | exports.wxssConverter = language_wxss_1.default; 10 | const index_1 = __importDefault(require("./language-js/index")); 11 | exports.jsConverter = index_1.default; 12 | function default_1(sourceCodes, options) { 13 | } 14 | exports.default = default_1; 15 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /dist/lib/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;AAAA,oEAA2C;AAIrB,wBAJf,uBAAa,CAIe;AAHnC,oEAA2C;AAGN,wBAH9B,uBAAa,CAG8B;AAFlD,gEAA6C;AAEpC,sBAFF,eAAW,CAEE;AAEpB,mBAAyB,WAAoB,EAAE,OAAa;AAE5D,CAAC;AAFD,4BAEC"} -------------------------------------------------------------------------------- /dist/lib/language-js/generator.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const generator_1 = __importDefault(require("@babel/generator")); 7 | function default_1(ast) { 8 | return generator_1.default(ast).code; 9 | } 10 | exports.default = default_1; 11 | //# sourceMappingURL=generator.js.map -------------------------------------------------------------------------------- /dist/lib/language-js/generator.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../src/language-js/generator.ts"],"names":[],"mappings":";;;;;AAAA,iEAAwC;AAExC,mBAAyB,GAAsB;IAC7C,OAAO,mBAAS,CAAC,GAAG,CAAC,CAAC,IAAI,CAAA;AAC5B,CAAC;AAFD,4BAEC"} -------------------------------------------------------------------------------- /dist/lib/language-js/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const parser_1 = __importDefault(require("./parser")); 7 | const transformation_1 = __importDefault(require("./transformation")); 8 | const generator_1 = __importDefault(require("./generator")); 9 | function default_1(sourceCode, options = { type: 'page' }) { 10 | const ast = parser_1.default(sourceCode); 11 | const distAst = transformation_1.default(ast, options); 12 | const distCode = generator_1.default(distAst); 13 | return distCode; 14 | } 15 | exports.default = default_1; 16 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /dist/lib/language-js/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/language-js/index.ts"],"names":[],"mappings":";;;;;AAAA,sDAA6B;AAC7B,sEAA0C;AAC1C,4DAAmC;AAGnC,mBAAyB,UAAmB,EAAE,UAAgB,EAAE,IAAI,EAAE,MAAM,EAAE;IAC5E,MAAM,GAAG,GAAsB,gBAAM,CAAC,UAAU,CAAC,CAAA;IAEjD,MAAM,OAAO,GAAG,wBAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IAEzC,MAAM,QAAQ,GAAY,mBAAS,CAAC,OAAO,CAAC,CAAA;IAE5C,OAAO,QAAQ,CAAA;AACjB,CAAC;AARD,4BAQC"} -------------------------------------------------------------------------------- /dist/lib/language-js/parser.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const parser_1 = require("@babel/parser"); 4 | function default_1(sourceCode) { 5 | return parser_1.parse(sourceCode, { 6 | sourceType: 'module' 7 | }); 8 | } 9 | exports.default = default_1; 10 | //# sourceMappingURL=parser.js.map -------------------------------------------------------------------------------- /dist/lib/language-js/parser.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../../src/language-js/parser.ts"],"names":[],"mappings":";;AAAA,0CAAqC;AAErC,mBAAyB,UAAmB;IAC1C,OAAO,cAAK,CAAC,UAAU,EAAE;QACvB,UAAU,EAAE,QAAQ;KACrB,CAAC,CAAA;AACJ,CAAC;AAJD,4BAIC"} -------------------------------------------------------------------------------- /dist/lib/language-js/transformation/api.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importStar = (this && this.__importStar) || function (mod) { 3 | if (mod && mod.__esModule) return mod; 4 | var result = {}; 5 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; 6 | result["default"] = mod; 7 | return result; 8 | }; 9 | Object.defineProperty(exports, "__esModule", { value: true }); 10 | const t = __importStar(require("@babel/types")); 11 | exports.default = (api, options = {}) => { 12 | return { 13 | visitor: { 14 | CallExpression(path) { 15 | const { node } = path; 16 | const callee = node.callee; 17 | if (t.isThisExpression(callee.object) && callee.property.name === 'setData') { 18 | if (node.arguments.length === 2) { 19 | const afterFunction = node.arguments[1]; 20 | path.insertAfter(afterFunction.body.body); 21 | } 22 | const props = node.arguments[0].properties.reverse(); 23 | props.forEach((prop) => { 24 | path.insertAfter(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), prop.key), prop.value)); 25 | }); 26 | path.remove(); 27 | } 28 | }, 29 | ThisExpression(path) { 30 | const parentNode = path.parentPath.node; 31 | if (t.isMemberExpression(parentNode) && parentNode.property.name === 'data') { 32 | path.parentPath.replaceWith(t.thisExpression()); 33 | } 34 | } 35 | } 36 | }; 37 | }; 38 | //# sourceMappingURL=api.js.map -------------------------------------------------------------------------------- /dist/lib/language-js/transformation/api.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"api.js","sourceRoot":"","sources":["../../../../src/language-js/transformation/api.ts"],"names":[],"mappings":";;;;;;;;;AAAA,gDAAiC;AAEjC,kBAAe,CAAC,GAAS,EAAE,UAAgB,EAAE,EAAoB,EAAE;IACjE,OAAO;QACL,OAAO,EAAE;YACP,cAAc,CAAE,IAAuC;gBACrD,MAAM,EAAE,IAAI,EAAE,GAAiC,IAAI,CAAA;gBACnD,MAAM,MAAM,GAAG,IAAI,CAAC,MAA4B,CAAA;gBAGhD,IAAI,CAAC,CAAC,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,KAAK,SAAS,EAAE;oBAE3E,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;wBAC/B,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAyB,CAAA;wBAC/D,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;qBAC1C;oBAED,MAAM,KAAK,GAAK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAwB,CAAC,UAAiC,CAAC,OAAO,EAAE,CAAA;oBACpG,KAAK,CAAC,OAAO,CAAC,CAAC,IAAuB,EAAE,EAAE;wBACxC,IAAI,CAAC,WAAW,CACd,CAAC,CAAC,oBAAoB,CAAC,GAAG,EAAE,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,cAAc,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,EAAG,IAAI,CAAC,KAAsB,CAAC,CAC5G,CAAA;oBACH,CAAC,CAAC,CAAA;oBAEF,IAAI,CAAC,MAAM,EAAE,CAAA;iBACd;YACH,CAAC;YACD,cAAc,CAAE,IAAI;gBAElB,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAA;gBACvC,IAAI,CAAC,CAAC,kBAAkB,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,IAAI,KAAK,MAAM,EAAE;oBAC3E,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,cAAc,EAAE,CAAC,CAAA;iBAChD;YACH,CAAC;SACF;KACF,CAAA;AACH,CAAC,CAAA"} -------------------------------------------------------------------------------- /dist/lib/language-js/transformation/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const traverse_1 = __importDefault(require("@babel/traverse")); 7 | const structure_1 = __importDefault(require("./structure")); 8 | const api_1 = __importDefault(require("./api")); 9 | const codeMods = [structure_1.default, api_1.default]; 10 | exports.default = (ast, options) => { 11 | const distAst = codeMods.reduce((prev, curr) => { 12 | traverse_1.default(prev, curr(null, options).visitor); 13 | return prev; 14 | }, ast); 15 | return distAst; 16 | }; 17 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /dist/lib/language-js/transformation/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/language-js/transformation/index.ts"],"names":[],"mappings":";;;;;AAAA,+DAAsC;AACtC,4DAA8C;AAC9C,gDAAkC;AAElC,MAAM,QAAQ,GAAqB,CAAC,mBAAoB,EAAE,aAAc,CAAC,CAAA;AAEzE,kBAAe,CAAC,GAAsB,EAAE,OAAa,EAAqB,EAAE;IAE1E,MAAM,OAAO,GAAS,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAQ,EAAE;QACzD,kBAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,CAAA;QAC3C,OAAO,IAAI,CAAA;IACb,CAAC,EAAE,GAAG,CAAC,CAAA;IACP,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"} -------------------------------------------------------------------------------- /dist/lib/language-js/transformation/structure.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importStar = (this && this.__importStar) || function (mod) { 3 | if (mod && mod.__esModule) return mod; 4 | var result = {}; 5 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; 6 | result["default"] = mod; 7 | return result; 8 | }; 9 | Object.defineProperty(exports, "__esModule", { value: true }); 10 | const t = __importStar(require("@babel/types")); 11 | function handleProperty(path, rootPath) { 12 | const { node } = path; 13 | if (t.isObjectExpression(node.value)) { 14 | const propsPath = path.get('value.properties'); 15 | const propTypePath = propsPath.filter((propPath) => t.isNodesEquivalent(propPath.node.key, t.identifier('type')))[0]; 16 | const typeNode = propTypePath.node.value; 17 | let watchPropNode = t.objectProperty(node.key, t.nullLiteral()); 18 | propsPath.forEach((propPath) => { 19 | const propNode = propPath.node; 20 | const keyName = propNode.key.name; 21 | const watchPropIndex = rootPath.findIndex((propPath) => t.isNodesEquivalent(propPath.node.key, t.identifier('watch'))); 22 | switch (keyName) { 23 | case 'value': 24 | if (t.isNodesEquivalent(typeNode, t.identifier('Object'))) { 25 | propPath.replaceWith(t.objectProperty(t.identifier('default'), t.arrowFunctionExpression([], propNode.value))); 26 | } 27 | else if (t.isNodesEquivalent(typeNode, t.identifier('Array'))) { 28 | propPath.replaceWith(t.objectProperty(t.identifier('default'), t.arrowFunctionExpression([], propNode.value))); 29 | } 30 | else { 31 | propPath.replaceWith(t.objectProperty(t.identifier('default'), propNode.value)); 32 | } 33 | break; 34 | case 'observer': 35 | if (t.isNodesEquivalent(typeNode, t.identifier('Object')) || t.isNodesEquivalent(typeNode, t.identifier('Array'))) { 36 | watchPropNode = t.objectProperty(node.key, t.objectExpression([ 37 | t.objectMethod('method', t.identifier('handler'), propNode.value.params, propNode.value.body), 38 | t.objectProperty(t.identifier('deep'), t.booleanLiteral(true)) 39 | ])); 40 | } 41 | else { 42 | watchPropNode = t.objectProperty(node.key, t.arrowFunctionExpression(propNode.value.params, propNode.value.body)); 43 | } 44 | if (watchPropIndex === -1) { 45 | rootPath[rootPath.length - 1].insertAfter(t.objectProperty(t.identifier('watch'), t.objectExpression([watchPropNode]))); 46 | } 47 | else { 48 | const propsPath = rootPath[watchPropIndex].get('value.properties'); 49 | if (propsPath.length) { 50 | propsPath[propsPath.length - 1].insertAfter(watchPropNode); 51 | } 52 | else { 53 | rootPath[watchPropIndex].replaceWith(t.objectProperty(t.identifier('watch'), t.objectExpression([watchPropNode]))); 54 | } 55 | } 56 | propPath.remove(); 57 | break; 58 | } 59 | }); 60 | } 61 | } 62 | function handleProperties(path, rootPath) { 63 | const { node } = path; 64 | const propsPath = path.get('value.properties'); 65 | propsPath.forEach((propPath) => { 66 | handleProperty(propPath, rootPath); 67 | }); 68 | path.replaceWith(t.objectProperty(t.identifier('props'), node.value)); 69 | } 70 | function handleData(path) { 71 | const { node } = path; 72 | path.replaceWith(t.objectProperty(t.identifier('data'), t.arrowFunctionExpression([], node.value))); 73 | } 74 | function handleLifeCycles(path) { 75 | const { node } = path; 76 | const keyName = node.key.name; 77 | const keyNameMap = { 78 | ready: 'mounted', 79 | attached: 'beforeMount', 80 | detached: 'destroyed', 81 | behaviors: 'mixins', 82 | onLoad: 'created', 83 | onReady: 'mounted', 84 | onUnload: 'destroyed' 85 | }; 86 | if (t.isObjectMethod(node)) { 87 | path.replaceWith(t.objectMethod('method', t.identifier(keyNameMap[keyName]), node.params, node.body)); 88 | } 89 | else if (t.isObjectProperty(node)) { 90 | const { value } = node; 91 | if (t.isFunctionExpression(value) || t.isArrowFunctionExpression(value)) { 92 | path.replaceWith(t.objectMethod('method', t.identifier(keyNameMap[keyName]), value.params, value.body)); 93 | } 94 | else { 95 | path.replaceWith(t.objectProperty(t.identifier(keyNameMap[keyName]), value)); 96 | } 97 | } 98 | } 99 | function handleOtherProperties(path, rootPath) { 100 | const { node } = path; 101 | const rootPropsPath = rootPath.get('arguments.0.properties'); 102 | const methodsPropIndex = rootPropsPath.findIndex((propPath) => propPath.node && t.isNodesEquivalent(propPath.node.key, t.identifier('methods'))); 103 | if (t.isObjectMethod(node) || (t.isArrowFunctionExpression(node.value) || t.isFunctionExpression(node.value))) { 104 | if (methodsPropIndex === -1) { 105 | rootPropsPath[rootPropsPath.length - 1].insertAfter(t.objectProperty(t.identifier('methods'), t.objectExpression([node]))); 106 | } 107 | else { 108 | const propsPath = rootPropsPath[methodsPropIndex].get('value.properties'); 109 | if (propsPath.length) { 110 | propsPath[propsPath.length - 1].insertAfter(node); 111 | } 112 | else { 113 | rootPropsPath[methodsPropIndex].replaceWith(t.objectProperty(t.identifier('methods'), t.objectExpression([node]))); 114 | } 115 | } 116 | path.remove(); 117 | } 118 | } 119 | exports.default = (api, options = {}) => { 120 | return { 121 | visitor: { 122 | CallExpression(path) { 123 | const { node } = path; 124 | const { callee } = node; 125 | const rootName = options.rootName || (options.type === 'page' ? 'Page' : 'Component'); 126 | if (options.type === 'page') { 127 | if (callee.name === rootName) { 128 | const pageArgNode = node.arguments[0]; 129 | const propsPath = path.get('arguments.0.properties'); 130 | propsPath.forEach((propPath) => { 131 | const { name } = propPath.node.key; 132 | switch (name) { 133 | case 'data': 134 | handleData(propPath); 135 | break; 136 | case 'onLoad': 137 | case 'onReady': 138 | case 'onUnload': 139 | handleLifeCycles(propPath); 140 | break; 141 | default: 142 | handleOtherProperties(propPath, path); 143 | } 144 | }); 145 | path.parentPath.replaceWith(t.exportDefaultDeclaration(pageArgNode)); 146 | } 147 | } 148 | else if (options.type === 'component') { 149 | if (callee.name === rootName) { 150 | const componentArgNode = node.arguments[0]; 151 | const propsPath = path.get('arguments.0.properties'); 152 | propsPath.forEach((propPath) => { 153 | const { name } = propPath.node.key; 154 | switch (name) { 155 | case 'properties': 156 | handleProperties(propPath, propsPath); 157 | break; 158 | case 'data': 159 | handleData(propPath); 160 | break; 161 | case 'attached': 162 | case 'detached': 163 | case 'behaviors': 164 | case 'ready': 165 | handleLifeCycles(propPath); 166 | break; 167 | default: 168 | handleOtherProperties(propPath, path); 169 | } 170 | }); 171 | path.parentPath.replaceWith(t.exportDefaultDeclaration(componentArgNode)); 172 | } 173 | } 174 | } 175 | } 176 | }; 177 | }; 178 | //# sourceMappingURL=structure.js.map -------------------------------------------------------------------------------- /dist/lib/language-js/transformation/structure.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"structure.js","sourceRoot":"","sources":["../../../../src/language-js/transformation/structure.ts"],"names":[],"mappings":";;;;;;;;;AAAA,gDAAiC;AAEjC,SAAS,cAAc,CAAE,IAAuC,EAAE,QAA6C;IAC7G,MAAM,EAAE,IAAI,EAAE,GAAiC,IAAI,CAAA;IAEnD,IAAI,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;QACpC,MAAM,SAAS,GAAI,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAwC,CAAA;QACtF,MAAM,YAAY,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,iBAAiB,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QACpH,MAAM,QAAQ,GAAG,YAAY,CAAC,IAAI,CAA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IAAI,CAAC,GAAG,CAAC,wBAAwB,CAAwC,CAAA;wBAG5F,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;4BAC7B,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAA;4BAElC,QAAQ,IAAI,EAAE;gCACZ,KAAK,YAAY;oCACf,gBAAgB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;oCACrC,MAAK;gCACP,KAAK,MAAM;oCACT,UAAU,CAAC,QAAQ,CAAC,CAAA;oCACpB,MAAK;gCAKP,KAAK,UAAU,CAAC;gCAChB,KAAK,UAAU,CAAC;gCAChB,KAAK,WAAW,CAAC;gCACjB,KAAK,OAAO;oCACV,gBAAgB,CAAC,QAAQ,CAAC,CAAA;oCAC1B,MAAK;gCACP;oCACE,qBAAqB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;6BACxC;wBACH,CAAC,CAAC,CAAA;wBAEF,IAAI,CAAC,UAAU,CAAC,WAAW,CACzB,CAAC,CAAC,wBAAwB,CAAC,gBAAgB,CAAC,CAC7C,CAAA;qBACF;iBACF;YACH,CAAC;SACF;KACF,CAAA;AACH,CAAC,CAAA"} -------------------------------------------------------------------------------- /dist/lib/language-wxml/generator.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var emptyTags = { 4 | area: 1, 5 | base: 1, 6 | basefont: 1, 7 | br: 1, 8 | col: 1, 9 | frame: 1, 10 | hr: 1, 11 | img: 1, 12 | input: 1, 13 | isindex: 1, 14 | link: 1, 15 | meta: 1, 16 | param: 1, 17 | embed: 1, 18 | '?xml': 1 19 | }; 20 | var ampRe = /&/g; 21 | var ltRe = //g; 23 | var quotRe = /"/g; 24 | var eqRe = /=/g; 25 | var config = { 26 | disableAttribEscape: false 27 | }; 28 | function escapeAttrib(s) { 29 | if (config.disableAttribEscape === true) { 30 | return s.toString(); 31 | } 32 | if (s == null) { 33 | return ''; 34 | } 35 | if (s.toString && typeof s.toString === 'function') { 36 | return s.toString().replace(ampRe, '&').replace(ltRe, '<').replace(gtRe, '>') 37 | .replace(quotRe, '"').replace(eqRe, '='); 38 | } 39 | else { 40 | return ''; 41 | } 42 | } 43 | function HTMLGenerator(item, parent, eachFn) { 44 | if (Array.isArray(item)) { 45 | return item.map(function (subitem) { 46 | return HTMLGenerator(subitem, parent, eachFn); 47 | }).join(''); 48 | } 49 | var orig = item; 50 | if (eachFn) { 51 | item = eachFn(item, parent); 52 | } 53 | if (typeof item !== 'undefined' && typeof item.type !== 'undefined') { 54 | switch (item.type) { 55 | case 'text': 56 | return item.data; 57 | case 'directive': 58 | return '<' + item.data + '>'; 59 | case 'comment': 60 | return ''; 61 | case 'style': 62 | case 'script': 63 | case 'tag': 64 | var result = '<' + item.name; 65 | if (item.attribs && Object.keys(item.attribs).length > 0) { 66 | result += ' ' + Object.keys(item.attribs).map(function (key) { 67 | return key + '="' + escapeAttrib(item.attribs[key]) + '"'; 68 | }).join(' '); 69 | } 70 | if (item.children) { 71 | if (!orig.render) { 72 | orig = parent; 73 | } 74 | result += '>' + HTMLGenerator(item.children, orig, eachFn) + (emptyTags[item.name] ? '' : ''); 75 | } 76 | else { 77 | if (emptyTags[item.name]) { 78 | result += '>'; 79 | } 80 | else { 81 | result += '>'; 82 | } 83 | } 84 | return result; 85 | case 'cdata': 86 | return ''; 87 | } 88 | } 89 | return item; 90 | } 91 | exports.default = HTMLGenerator; 92 | HTMLGenerator.configure = function (userConfig) { 93 | if (userConfig !== undefined) { 94 | for (const k in config) { 95 | if (userConfig[k] !== undefined) { 96 | config[k] = userConfig[k]; 97 | } 98 | } 99 | } 100 | }; 101 | //# sourceMappingURL=generator.js.map -------------------------------------------------------------------------------- /dist/lib/language-wxml/generator.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../src/language-wxml/generator.ts"],"names":[],"mappings":";;AAAA,IAAI,SAAS,GA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IAAI,CAAC,QAAQ,EAAE;oBAGjB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;wBAChB,IAAI,GAAG,MAAM,CAAA;qBACd;oBACD,MAAM,IAAI,GAAG,GAAG,aAAa,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,CAAA;iBAClH;qBAAM;oBACL,IAAI,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;wBACxB,MAAM,IAAI,GAAG,CAAA;qBACd;yBAAM;wBACL,MAAM,IAAI,KAAK,GAAG,IAAI,CAAC,IAAI,GAAG,GAAG,CAAA;qBAClC;iBACF;gBACD,OAAO,MAAM,CAAA;YACf,KAAK,OAAO;gBACV,OAAO,UAAU,GAAG,IAAI,CAAC,IAAI,GAAG,KAAK,CAAA;SACxC;KACF;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAlDD,gCAkDC;AAED,aAAa,CAAC,SAAS,GAAG,UAAU,UAAgB;IAClD,IAAI,UAAU,KAAK,SAAS,EAAE;QAC5B,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE;YACtB,IAAI,UAAU,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE;gBAC/B,MAAM,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;aAC1B;SACF;KACF;AACH,CAAC,CAAA"} -------------------------------------------------------------------------------- /dist/lib/language-wxml/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const parser_1 = __importDefault(require("./parser")); 7 | const transformer_1 = __importDefault(require("./transformer")); 8 | const generator_1 = __importDefault(require("./generator")); 9 | async function default_1(sourceCode, options = {}) { 10 | const ast = await parser_1.default(sourceCode); 11 | const distAst = await transformer_1.default(ast, options); 12 | generator_1.default.configure({ 13 | disableAttribEscape: true 14 | }); 15 | const distCode = generator_1.default(distAst); 16 | return distCode; 17 | } 18 | exports.default = default_1; 19 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /dist/lib/language-wxml/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/language-wxml/index.ts"],"names":[],"mappings":";;;;;AAAA,sDAA6B;AAC7B,gEAAuC;AACvC,4DAAmC;AAGpB,KAAK,oBAAW,UAAmB,EAAE,UAAgB,EAAG;IACrE,MAAM,GAAG,GAAG,MAAM,gBAAM,CAAC,UAAU,CAAC,CAAA;IAEpC,MAAM,OAAO,GAAG,MAAM,qBAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IAE/C,mBAAS,CAAC,SAAS,CAAC;QAClB,mBAAmB,EAAE,IAAI;KAC1B,CAAC,CAAA;IACF,MAAM,QAAQ,GAAY,mBAAS,CAAC,OAAO,CAAC,CAAA;IAE5C,OAAO,QAAQ,CAAA;AACjB,CAAC;AAXD,4BAWC"} -------------------------------------------------------------------------------- /dist/lib/language-wxml/parser.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const htmlparser2_1 = require("htmlparser2"); 4 | function parse(sourceCode) { 5 | return new Promise((resolve, reject) => { 6 | const handler = new htmlparser2_1.DomHandler((err, dom) => { 7 | if (err) { 8 | reject(err); 9 | } 10 | resolve(dom); 11 | }); 12 | const parser = new htmlparser2_1.Parser(handler, { 13 | xmlMode: true, 14 | lowerCaseTags: false, 15 | recognizeSelfClosing: true 16 | }); 17 | parser.write(sourceCode); 18 | parser.end(); 19 | }); 20 | } 21 | exports.default = parse; 22 | //# sourceMappingURL=parser.js.map -------------------------------------------------------------------------------- /dist/lib/language-wxml/parser.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../../src/language-wxml/parser.ts"],"names":[],"mappings":";;AAAA,6CAAgD;AAEhD,SAAwB,KAAK,CAAE,UAAmB;IAChD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,OAAO,GAAG,IAAI,wBAAU,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YAC1C,IAAI,GAAG,EAAE;gBACP,MAAM,CAAC,GAAG,CAAC,CAAA;aACZ;YAED,OAAO,CAAC,GAAG,CAAC,CAAA;QACd,CAAC,CAAC,CAAA;QAEF,MAAM,MAAM,GAAG,IAAI,oBAAM,CAAC,OAAO,EAAE;YACjC,OAAO,EAAE,IAAI;YACb,aAAa,EAAE,KAAK;YACpB,oBAAoB,EAAE,IAAI;SAC3B,CAAC,CAAA;QACF,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;QACxB,MAAM,CAAC,GAAG,EAAE,CAAA;IACd,CAAC,CAAC,CAAA;AACJ,CAAC;AAlBD,wBAkBC"} -------------------------------------------------------------------------------- /dist/lib/language-wxml/transformer.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | function dynamicValue(value) { 4 | if (!value) 5 | return []; 6 | return value.match(/{{(.*?)}}/g); 7 | } 8 | function tagTransformer(node) { 9 | switch (node.name) { 10 | case 'view': 11 | node.name = 'div'; 12 | break; 13 | case 'text': 14 | node.name = 'span'; 15 | break; 16 | case 'block': 17 | node.name = 'template'; 18 | break; 19 | case 'image': 20 | node.name = 'img'; 21 | break; 22 | case 'mf-page': 23 | node.name = 'div'; 24 | break; 25 | default: 26 | } 27 | } 28 | function handleClassAttribute(value, node) { 29 | const regValue = dynamicValue(value); 30 | if (regValue && regValue.length) { 31 | const dynamicClassValue = regValue.map((item) => item.replace(/{{(.*?)}}/, '$1')); 32 | node.attribs[':class'] = `[${dynamicClassValue}]`; 33 | const restValue = regValue.reduce((accu, curr) => { 34 | return accu.replace(curr, ''); 35 | }, value); 36 | node.attribs.class = restValue.trim(); 37 | } 38 | } 39 | function handleStyleAttribute(value, node) { 40 | const styleList = value.split(';'); 41 | const normalStyle = []; 42 | const dynamicStyle = {}; 43 | let finalDynamicStyle = ''; 44 | styleList.forEach((style) => { 45 | const regValue = dynamicValue(style); 46 | if (regValue && regValue.length) { 47 | let [property, styleValue] = style.split(':'); 48 | let finalStyleValue = ''; 49 | property = property.replace(/-(\w)/g, (all, letter) => letter.toUpperCase()).trim(); 50 | const firstSplit = styleValue.split('{{'); 51 | let secondSplit = []; 52 | firstSplit.forEach((item) => { 53 | secondSplit = secondSplit.concat(item.split('}}')); 54 | }); 55 | secondSplit.forEach((part, index) => { 56 | if (!part) 57 | return; 58 | if (finalStyleValue.length) 59 | finalStyleValue += (index > 0 && '+') || ''; 60 | finalStyleValue += (index % 2 ? part : JSON.stringify(part.trim())); 61 | }); 62 | const transferFinalStyleValue = finalStyleValue.replace(/([\d]+)rpx/g, (m, $1) => { 63 | const newPx = $1.replace(/(^:)|(:$)/g, ''); 64 | return `${newPx * 0.5}px`; 65 | }); 66 | dynamicStyle[property] = transferFinalStyleValue; 67 | } 68 | else { 69 | const css = style.trim(); 70 | const transferFinalStyleValue = css.replace(/([\d]+)rpx/g, (m, $1) => { 71 | const newPx = $1.replace(/(^:)|(:$)/g, ''); 72 | return `${newPx * 0.5}px`; 73 | }); 74 | normalStyle.push(transferFinalStyleValue); 75 | } 76 | }); 77 | node.attribs.style = normalStyle.join(';'); 78 | if (Object.keys(dynamicStyle).length) { 79 | finalDynamicStyle = '{ '; 80 | Object.keys(dynamicStyle).forEach((property) => { 81 | const value = dynamicStyle[property]; 82 | finalDynamicStyle += property; 83 | finalDynamicStyle += ': '; 84 | finalDynamicStyle += value.replace(/"/g, "'"); 85 | finalDynamicStyle += ';'; 86 | }); 87 | finalDynamicStyle += ' }'; 88 | node.attribs[':style'] = finalDynamicStyle; 89 | } 90 | } 91 | function handleBindAttribute(value, attribute, node) { 92 | let eventName = ''; 93 | if (attribute.indexOf(':') !== -1) { 94 | eventName = attribute.split(':')[1]; 95 | } 96 | else { 97 | eventName = attribute.substr(4); 98 | } 99 | if (eventName === 'tap') 100 | eventName = 'click'; 101 | node.attribs[`@${eventName}`] = `${value}($event)`; 102 | delete node.attribs[attribute]; 103 | } 104 | function handleCatchAttribute(value, attribute, node) { 105 | let eventName = ''; 106 | if (attribute.indexOf(':') !== -1) { 107 | eventName = attribute.split(':')[1]; 108 | } 109 | else { 110 | eventName = attribute.substr(5); 111 | } 112 | if (eventName === 'tap') 113 | eventName = 'click'; 114 | node.attribs[`@${eventName}.stop`] = value; 115 | delete node.attribs[attribute]; 116 | } 117 | function handleWXAttribute(value, attribute, node) { 118 | const attrName = attribute.split(':')[1]; 119 | switch (attrName) { 120 | case 'if': 121 | node.attribs['v-if'] = value.replace(/{{(.*?)}}/, '$1').trim(); 122 | delete node.attribs[attribute]; 123 | break; 124 | case 'else': 125 | node.attribs['v-else'] = ''; 126 | delete node.attribs[attribute]; 127 | break; 128 | case 'elif': 129 | node.attribs['v-else-if'] = value.replace(/{{(.*?)}}/, '$1').trim(); 130 | delete node.attribs[attribute]; 131 | break; 132 | case 'key': 133 | node.attribs[':key'] = value.replace(/{{(.*?)}}/, '$1').trim(); 134 | delete node.attribs[attribute]; 135 | break; 136 | case 'for': 137 | const forItem = node.attribs['wx:for-item']; 138 | const forIndex = node.attribs['wx:for-index']; 139 | const forContent = value.replace(/{{(.*?)}}/, '$1').trim(); 140 | node.attribs['v-for'] = `(${forItem || 'item'}, ${forIndex || 'index'}) in ${forContent}`; 141 | delete node.attribs['wx:for-item']; 142 | delete node.attribs['wx:for-index']; 143 | delete node.attribs[attribute]; 144 | break; 145 | } 146 | } 147 | function handleElseAttribute(value, attribute, node) { 148 | if (dynamicValue(value) && dynamicValue(value).length) { 149 | node.attribs[`:${attribute}`] = value.replace(/{{(.*?)}}/, '$1').trim(); 150 | delete node.attribs[attribute]; 151 | } 152 | } 153 | function attributeTransformer(node) { 154 | Object.keys(node.attribs).forEach((attribute) => { 155 | const value = node.attribs[attribute]; 156 | if (attribute === 'class') { 157 | handleClassAttribute(value, node); 158 | } 159 | else if (attribute === 'style') { 160 | handleStyleAttribute(value, node); 161 | } 162 | else if (attribute.match(/^bind/)) { 163 | handleBindAttribute(value, attribute, node); 164 | } 165 | else if (attribute.match(/^catch/)) { 166 | handleCatchAttribute(value, attribute, node); 167 | } 168 | else if (attribute.match(/^wx:/)) { 169 | handleWXAttribute(value, attribute, node); 170 | } 171 | else if (attribute === 'mfConfig') { 172 | delete node.attribs[attribute]; 173 | } 174 | else { 175 | handleElseAttribute(value, attribute, node); 176 | } 177 | }); 178 | } 179 | async function templateTransformer(ast, options) { 180 | for (let i = 0; i < ast.length; i++) { 181 | const node = ast[i]; 182 | switch (node.type) { 183 | case 'tag': 184 | tagTransformer(node); 185 | attributeTransformer(node); 186 | break; 187 | default: 188 | } 189 | if (node.children) { 190 | templateTransformer(node.children, options); 191 | } 192 | } 193 | return ast; 194 | } 195 | exports.default = templateTransformer; 196 | //# sourceMappingURL=transformer.js.map -------------------------------------------------------------------------------- /dist/lib/language-wxml/transformer.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"transformer.js","sourceRoot":"","sources":["../../../src/language-wxml/transformer.ts"],"names":[],"mappings":";;AAAA,SAAS,YAAY,CAAE,KAAW;IAChC,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAA;IACrB,OAAO,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;AAClC,CAAC;AAED,SAAS,cAAc,CAAE,IAAU;IACjC,QAAQ,IAAI,CAAC,IAAI,EAAE;QACjB,KAAK,MAAM;YACT,IAAI,CAAC,IAAI,GAAG,KAAK,CAAA;YACjB,MAAK;QAEP,KAAK,MAAM;YACT,IAAI,CAAC,IAAI,GAAG,MAAM,CAAA;YAClB,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CAAC,CAAC,CAAA;AACJ,CAAC;AAEc,KAAK,UAAU,mBAAmB,CAAE,GAAS,EAAE,OAAa;IACzE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACnC,MAAM,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;QAEnB,QAAQ,IAAI,CAAC,IAAI,EAAE;YACjB,KAAK,KAAK;gBACR,cAAc,CAAC,IAAI,CAAC,CAAA;gBACpB,oBAAoB,CAAC,IAAI,CAAC,CAAA;gBAC1B,MAAK;YAEP,QAAQ;SACT;QAED,IAAI,IAAI,CAAC,QAAQ,EAAE;YACjB,mBAAmB,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;SAC5C;KACF;IAED,OAAO,GAAG,CAAA;AACZ,CAAC;AAnBD,sCAmBC"} -------------------------------------------------------------------------------- /dist/lib/language-wxss/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const transformer_1 = __importDefault(require("./transformer")); 7 | function default_1(sourceCode, options = { type: 'page' }) { 8 | const distCode = transformer_1.default(sourceCode, options); 9 | return distCode; 10 | } 11 | exports.default = default_1; 12 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /dist/lib/language-wxss/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/language-wxss/index.ts"],"names":[],"mappings":";;;;;AAAA,gEAAuC;AAGvC,mBAAyB,UAAmB,EAAE,UAAgB,EAAE,IAAI,EAAE,MAAM,EAAE;IAC5E,MAAM,QAAQ,GAAG,qBAAW,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;IAEjD,OAAO,QAAQ,CAAA;AACjB,CAAC;AAJD,4BAIC"} -------------------------------------------------------------------------------- /dist/lib/language-wxss/transformer.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | function styleTransformer(sourceCode, options) { 4 | const css = sourceCode.replace(/([\d]+)rpx/g, (m, $1) => { 5 | const newPx = $1.replace(/(^:)|(:$)/g, ''); 6 | return `${newPx * 0.5}px`; 7 | }); 8 | return css; 9 | } 10 | exports.default = styleTransformer; 11 | //# sourceMappingURL=transformer.js.map 12 | -------------------------------------------------------------------------------- /dist/lib/language-wxss/transformer.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"transformer.js","sourceRoot":"","sources":["../../../src/language-wxss/transformer.ts"],"names":[],"mappings":";;AAAA,SAAwB,gBAAgB,CAAE,UAAmB,EAAE,OAAa;IAC1E,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE;QACtD,MAAM,KAAK,GAAG,EAAE,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAA;QAC1C,OAAO,GAAG,KAAK,GAAG,GAAG,IAAI,CAAA;IAC3B,CAAC,CAAC,CAAA;IACF,OAAO,GAAG,CAAA;AACZ,CAAC;AAND,mCAMC"} -------------------------------------------------------------------------------- /dist/yu_gong.js: -------------------------------------------------------------------------------- 1 | !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("htmlparser2"),require("@babel/parser"),require("@babel/traverse"),require("@babel/types"),require("@babel/generator")):"function"==typeof define&&define.amd?define(["exports","htmlparser2","@babel/parser","@babel/traverse","@babel/types","@babel/generator"],t):t((e=e||self).YG={},e.htmlparser2,e.parser$2,e.traverse,e.types,e.generator$2)}(this,(function(e,t,r,a,n,i){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t,r=r&&r.hasOwnProperty("default")?r.default:r,a=a&&a.hasOwnProperty("default")?a.default:a,n=n&&n.hasOwnProperty("default")?n.default:n,i=i&&i.hasOwnProperty("default")?i.default:i;var o="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function s(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function l(e,t){return e(t={exports:{}},t.exports),t.exports}var c=l((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.default=function(e){return new Promise((r,a)=>{const n=new t.DomHandler((e,t)=>{e&&a(e),r(t)}),i=new t.Parser(n,{xmlMode:!0,lowerCaseTags:!1,recognizeSelfClosing:!0});i.write(e),i.end()})}}));s(c);var u=l((function(e,t){function r(e){return e?e.match(/{{(.*?)}}/g):[]}function a(e){switch(e.name){case"view":e.name="div";break;case"text":e.name="span";break;case"block":e.name="template";break;case"image":e.name="img";break;case"mf-page":e.name="div"}}function n(e){Object.keys(e.attribs).forEach(t=>{const a=e.attribs[t];"class"===t?function(e,t){const a=r(e);if(a&&a.length){const r=a.map(e=>e.replace(/{{(.*?)}}/,"$1"));t.attribs[":class"]=`[${r}]`;const n=a.reduce((e,t)=>e.replace(t,""),e);t.attribs.class=n.trim()}}(a,e):"style"===t?function(e,t){const a=e.split(";"),n=[],i={};let o="";a.forEach(e=>{const t=r(e);if(t&&t.length){let[t,r]=e.split(":"),a="";t=t.replace(/-(\w)/g,(e,t)=>t.toUpperCase()).trim();const n=r.split("{{");let o=[];n.forEach(e=>{o=o.concat(e.split("}}"))}),o.forEach((e,t)=>{e&&(a.length&&(a+=t>0?"+":""),a+=t%2?e:JSON.stringify(e.trim()))});const s=a.replace(/([\d]+)rpx/g,(e,t)=>`${.5*t.replace(/(^:)|(:$)/g,"")}px`);i[t]=s}else{const t=e.trim().replace(/([\d]+)rpx/g,(e,t)=>`${.5*t.replace(/(^:)|(:$)/g,"")}px`);n.push(t)}}),t.attribs.style=n.join(";"),Object.keys(i).length&&(o="{ ",Object.keys(i).forEach(e=>{const t=i[e];o+=e,o+=": ",o+=t.replace(/"/g,"'"),o+=";"}),o+=" }",t.attribs[":style"]=o)}(a,e):t.match(/^bind/)?function(e,t,r){let a="";a=-1!==t.indexOf(":")?t.split(":")[1]:t.substr(4),"tap"===a&&(a="click"),r.attribs[`@${a}`]=`${e}($event)`,delete r.attribs[t]}(a,t,e):t.match(/^catch/)?function(e,t,r){let a="";a=-1!==t.indexOf(":")?t.split(":")[1]:t.substr(5),"tap"===a&&(a="click"),r.attribs[`@${a}.stop`]=e,delete r.attribs[t]}(a,t,e):t.match(/^wx:/)?function(e,t,r){switch(t.split(":")[1]){case"if":r.attribs["v-if"]=e.replace(/{{(.*?)}}/,"$1").trim(),delete r.attribs[t];break;case"else":r.attribs["v-else"]="",delete r.attribs[t];break;case"elif":r.attribs["v-else-if"]=e.replace(/{{(.*?)}}/,"$1").trim(),delete r.attribs[t];break;case"key":r.attribs[":key"]=e.replace(/{{(.*?)}}/,"$1").trim(),delete r.attribs[t];break;case"for":const a=r.attribs["wx:for-item"],n=r.attribs["wx:for-index"],i=e.replace(/{{(.*?)}}/,"$1").trim();r.attribs["v-for"]=`(${a||"item"}, ${n||"index"}) in ${i}`,delete r.attribs["wx:for-item"],delete r.attribs["wx:for-index"],delete r.attribs[t]}}(a,t,e):"mfConfig"===t?delete e.attribs[t]:function(e,t,a){r(e)&&r(e).length&&(a.attribs[`:${t}`]=e.replace(/{{(.*?)}}/,"$1").trim(),delete a.attribs[t])}(a,t,e)})}Object.defineProperty(t,"__esModule",{value:!0}),t.default=async function e(t,r){for(let r=0;r/g,o=/"/g,s=/=/g,l={disableAttribEscape:!1};function c(e,t,u){if(Array.isArray(e))return e.map((function(e){return c(e,t,u)})).join("");var d=e;if(u&&(e=u(e,t)),void 0!==e&&void 0!==e.type)switch(e.type){case"text":return e.data;case"directive":return"<"+e.data+">";case"comment":return"\x3c!--"+e.data+"--\x3e";case"style":case"script":case"tag":var f="<"+e.name;return e.attribs&&Object.keys(e.attribs).length>0&&(f+=" "+Object.keys(e.attribs).map((function(t){return t+'="'+(r=e.attribs[t],!0===l.disableAttribEscape?r.toString():null==r?"":r.toString&&"function"==typeof r.toString?r.toString().replace(a,"&").replace(n,"<").replace(i,">").replace(o,""").replace(s,"="):"")+'"';var r})).join(" ")),e.children?(d.render||(d=t),f+=">"+c(e.children,d,u)+(r[e.name]?"":"")):r[e.name]?f+=">":f+=">",f;case"cdata":return""}return e}t.default=c,c.configure=function(e){if(void 0!==e)for(const t in l)void 0!==e[t]&&(l[t]=e[t])}}));s(d);var f=l((function(e,t){var r=o&&o.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=r(c),n=r(u),i=r(d);t.default=async function(e,t={}){const r=await a.default(e),o=await n.default(r,t);return i.default.configure({disableAttribEscape:!0}),i.default(o)}}));s(f);var p=l((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){return e.replace(/([\d]+)rpx/g,(e,t)=>`${.5*t.replace(/(^:)|(:$)/g,"")}px`)}}));s(p);var b=l((function(e,t){var r=o&&o.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=r(p);t.default=function(e,t={type:"page"}){return a.default(e,t)}}));s(b);var v=l((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){return r.parse(e,{sourceType:"module"})}}));s(v);var m=l((function(e,t){var r=o&&o.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t};Object.defineProperty(t,"__esModule",{value:!0});const a=r(n);function i(e,t){const{node:r}=e;e.get("value.properties").forEach(e=>{!function(e,t){const{node:r}=e;if(a.isObjectExpression(r.value)){const n=e.get("value.properties"),i=n.filter(e=>a.isNodesEquivalent(e.node.key,a.identifier("type")))[0].node.value;let o=a.objectProperty(r.key,a.nullLiteral());n.forEach(e=>{const n=e.node,s=n.key.name,l=t.findIndex(e=>a.isNodesEquivalent(e.node.key,a.identifier("watch")));switch(s){case"value":a.isNodesEquivalent(i,a.identifier("Object"))?e.replaceWith(a.objectProperty(a.identifier("default"),a.arrowFunctionExpression([],n.value))):a.isNodesEquivalent(i,a.identifier("Array"))?e.replaceWith(a.objectProperty(a.identifier("default"),a.arrowFunctionExpression([],n.value))):e.replaceWith(a.objectProperty(a.identifier("default"),n.value));break;case"observer":if(o=a.isNodesEquivalent(i,a.identifier("Object"))||a.isNodesEquivalent(i,a.identifier("Array"))?a.objectProperty(r.key,a.objectExpression([a.objectMethod("method",a.identifier("handler"),n.value.params,n.value.body),a.objectProperty(a.identifier("deep"),a.booleanLiteral(!0))])):a.objectProperty(r.key,a.arrowFunctionExpression(n.value.params,n.value.body)),-1===l)t[t.length-1].insertAfter(a.objectProperty(a.identifier("watch"),a.objectExpression([o])));else{const e=t[l].get("value.properties");e.length?e[e.length-1].insertAfter(o):t[l].replaceWith(a.objectProperty(a.identifier("watch"),a.objectExpression([o])))}e.remove()}})}}(e,t)}),e.replaceWith(a.objectProperty(a.identifier("props"),r.value))}function s(e){const{node:t}=e;e.replaceWith(a.objectProperty(a.identifier("data"),a.arrowFunctionExpression([],t.value)))}function l(e){const{node:t}=e,r=t.key.name,n={ready:"mounted",attached:"beforeMount",detached:"destroyed",behaviors:"mixins",onLoad:"created",onReady:"mounted",onUnload:"destroyed"};if(a.isObjectMethod(t))e.replaceWith(a.objectMethod("method",a.identifier(n[r]),t.params,t.body));else if(a.isObjectProperty(t)){const{value:i}=t;a.isFunctionExpression(i)||a.isArrowFunctionExpression(i)?e.replaceWith(a.objectMethod("method",a.identifier(n[r]),i.params,i.body)):e.replaceWith(a.objectProperty(a.identifier(n[r]),i))}}function c(e,t){const{node:r}=e,n=t.get("arguments.0.properties"),i=n.findIndex(e=>e.node&&a.isNodesEquivalent(e.node.key,a.identifier("methods")));if(a.isObjectMethod(r)||a.isArrowFunctionExpression(r.value)||a.isFunctionExpression(r.value)){if(-1===i)n[n.length-1].insertAfter(a.objectProperty(a.identifier("methods"),a.objectExpression([r])));else{const e=n[i].get("value.properties");e.length?e[e.length-1].insertAfter(r):n[i].replaceWith(a.objectProperty(a.identifier("methods"),a.objectExpression([r])))}e.remove()}}t.default=(e,t={})=>({visitor:{CallExpression(e){const{node:r}=e,{callee:n}=r,o=t.rootName||("page"===t.type?"Page":"Component");if("page"===t.type){if(n.name===o){const t=r.arguments[0];e.get("arguments.0.properties").forEach(t=>{const{name:r}=t.node.key;switch(r){case"data":s(t);break;case"onLoad":case"onReady":case"onUnload":l(t);break;default:c(t,e)}}),e.parentPath.replaceWith(a.exportDefaultDeclaration(t))}}else if("component"===t.type&&n.name===o){const t=r.arguments[0],n=e.get("arguments.0.properties");n.forEach(t=>{const{name:r}=t.node.key;switch(r){case"properties":i(t,n);break;case"data":s(t);break;case"attached":case"detached":case"behaviors":case"ready":l(t);break;default:c(t,e)}}),e.parentPath.replaceWith(a.exportDefaultDeclaration(t))}}}})}));s(m);var y=l((function(e,t){var r=o&&o.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t};Object.defineProperty(t,"__esModule",{value:!0});const a=r(n);t.default=(e,t={})=>({visitor:{CallExpression(e){const{node:t}=e,r=t.callee;if(a.isThisExpression(r.object)&&"setData"===r.property.name){if(2===t.arguments.length){const r=t.arguments[1];e.insertAfter(r.body.body)}t.arguments[0].properties.reverse().forEach(t=>{e.insertAfter(a.assignmentExpression("=",a.memberExpression(a.thisExpression(),t.key),t.value))}),e.remove()}},ThisExpression(e){const t=e.parentPath.node;a.isMemberExpression(t)&&"data"===t.property.name&&e.parentPath.replaceWith(a.thisExpression())}}})}));s(y);var h=l((function(e,t){var r=o&&o.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const n=r(a),i=r(m),s=r(y),l=[i.default,s.default];t.default=(e,t)=>l.reduce((e,r)=>(n.default(e,r(null,t).visitor),e),e)}));s(h);var g=l((function(e,t){var r=o&&o.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=r(i);t.default=function(e){return a.default(e).code}}));s(g);var x=l((function(e,t){var r=o&&o.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=r(v),n=r(h),i=r(g);t.default=function(e,t={type:"page"}){const r=a.default(e),o=n.default(r,t);return i.default(o)}}));s(x);var _=l((function(e,t){var r=o&&o.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=r(f);t.wxmlConverter=a.default;const n=r(b);t.wxssConverter=n.default;const i=r(x);t.jsConverter=i.default,t.default=function(e,t){}})),j=s(_),w=_.wxmlConverter,P=_.wxssConverter,E=_.jsConverter;e.default=j,e.jsConverter=E,e.wxmlConverter=w,e.wxssConverter=P,Object.defineProperty(e,"__esModule",{value:!0})})); 2 | //# sourceMappingURL=yu_gong.js.map 3 | -------------------------------------------------------------------------------- /dist/yu_gong.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"yu_gong.js","sources":["lib/language-wxml/parser.js","lib/language-wxml/transformer.js","lib/language-wxml/generator.js","lib/language-wxml/index.js","lib/language-wxss/transformer.js","lib/language-wxss/index.js","lib/language-js/parser.js","lib/language-js/transformation/structure.js","lib/language-js/transformation/api.js","lib/language-js/transformation/index.js","lib/language-js/generator.js","lib/language-js/index.js","lib/index.js"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst htmlparser2_1 = require(\"htmlparser2\");\nfunction parse(sourceCode) {\n return new Promise((resolve, reject) => {\n const handler = new htmlparser2_1.DomHandler((err, dom) => {\n if (err) {\n reject(err);\n }\n resolve(dom);\n });\n const parser = new htmlparser2_1.Parser(handler, {\n xmlMode: true,\n lowerCaseTags: false,\n recognizeSelfClosing: true\n });\n parser.write(sourceCode);\n parser.end();\n });\n}\nexports.default = parse;\n//# sourceMappingURL=parser.js.map","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nfunction dynamicValue(value) {\n if (!value)\n return [];\n return value.match(/{{(.*?)}}/g);\n}\nfunction tagTransformer(node) {\n switch (node.name) {\n case 'view':\n node.name = 'div';\n break;\n case 'text':\n node.name = 'span';\n break;\n case 'block':\n node.name = 'template';\n break;\n case 'image':\n node.name = 'img';\n break;\n case 'mf-page':\n node.name = 'div';\n break;\n default:\n }\n}\nfunction handleClassAttribute(value, node) {\n const regValue = dynamicValue(value);\n if (regValue && regValue.length) {\n const dynamicClassValue = regValue.map((item) => item.replace(/{{(.*?)}}/, '$1'));\n node.attribs[':class'] = `[${dynamicClassValue}]`;\n const restValue = regValue.reduce((accu, curr) => {\n return accu.replace(curr, '');\n }, value);\n node.attribs.class = restValue.trim();\n }\n}\nfunction handleStyleAttribute(value, node) {\n const styleList = value.split(';');\n const normalStyle = [];\n const dynamicStyle = {};\n let finalDynamicStyle = '';\n styleList.forEach((style) => {\n const regValue = dynamicValue(style);\n if (regValue && regValue.length) {\n let [property, styleValue] = style.split(':');\n let finalStyleValue = '';\n property = property.replace(/-(\\w)/g, (all, letter) => letter.toUpperCase()).trim();\n const firstSplit = styleValue.split('{{');\n let secondSplit = [];\n firstSplit.forEach((item) => {\n secondSplit = secondSplit.concat(item.split('}}'));\n });\n secondSplit.forEach((part, index) => {\n if (!part)\n return;\n if (finalStyleValue.length)\n finalStyleValue += (index > 0 && '+') || '';\n finalStyleValue += (index % 2 ? part : JSON.stringify(part.trim()));\n });\n const transferFinalStyleValue = finalStyleValue.replace(/([\\d]+)rpx/g, (m, $1) => {\n const newPx = $1.replace(/(^:)|(:$)/g, '');\n return `${newPx * 0.5}px`;\n });\n dynamicStyle[property] = transferFinalStyleValue;\n }\n else {\n const css = style.trim();\n const transferFinalStyleValue = css.replace(/([\\d]+)rpx/g, (m, $1) => {\n const newPx = $1.replace(/(^:)|(:$)/g, '');\n return `${newPx * 0.5}px`;\n });\n normalStyle.push(transferFinalStyleValue);\n }\n });\n node.attribs.style = normalStyle.join(';');\n if (Object.keys(dynamicStyle).length) {\n finalDynamicStyle = '{ ';\n Object.keys(dynamicStyle).forEach((property) => {\n const value = dynamicStyle[property];\n finalDynamicStyle += property;\n finalDynamicStyle += ': ';\n finalDynamicStyle += value.replace(/\"/g, \"'\");\n finalDynamicStyle += ';';\n });\n finalDynamicStyle += ' }';\n node.attribs[':style'] = finalDynamicStyle;\n }\n}\nfunction handleBindAttribute(value, attribute, node) {\n let eventName = '';\n if (attribute.indexOf(':') !== -1) {\n eventName = attribute.split(':')[1];\n }\n else {\n eventName = attribute.substr(4);\n }\n if (eventName === 'tap')\n eventName = 'click';\n node.attribs[`@${eventName}`] = `${value}($event)`;\n delete node.attribs[attribute];\n}\nfunction handleCatchAttribute(value, attribute, node) {\n let eventName = '';\n if (attribute.indexOf(':') !== -1) {\n eventName = attribute.split(':')[1];\n }\n else {\n eventName = attribute.substr(5);\n }\n if (eventName === 'tap')\n eventName = 'click';\n node.attribs[`@${eventName}.stop`] = value;\n delete node.attribs[attribute];\n}\nfunction handleWXAttribute(value, attribute, node) {\n const attrName = attribute.split(':')[1];\n switch (attrName) {\n case 'if':\n node.attribs['v-if'] = value.replace(/{{(.*?)}}/, '$1').trim();\n delete node.attribs[attribute];\n break;\n case 'else':\n node.attribs['v-else'] = '';\n delete node.attribs[attribute];\n break;\n case 'elif':\n node.attribs['v-else-if'] = value.replace(/{{(.*?)}}/, '$1').trim();\n delete node.attribs[attribute];\n break;\n case 'key':\n node.attribs[':key'] = value.replace(/{{(.*?)}}/, '$1').trim();\n delete node.attribs[attribute];\n break;\n case 'for':\n const forItem = node.attribs['wx:for-item'];\n const forIndex = node.attribs['wx:for-index'];\n const forContent = value.replace(/{{(.*?)}}/, '$1').trim();\n node.attribs['v-for'] = `(${forItem || 'item'}, ${forIndex || 'index'}) in ${forContent}`;\n delete node.attribs['wx:for-item'];\n delete node.attribs['wx:for-index'];\n delete node.attribs[attribute];\n break;\n }\n}\nfunction handleElseAttribute(value, attribute, node) {\n if (dynamicValue(value) && dynamicValue(value).length) {\n node.attribs[`:${attribute}`] = value.replace(/{{(.*?)}}/, '$1').trim();\n delete node.attribs[attribute];\n }\n}\nfunction attributeTransformer(node) {\n Object.keys(node.attribs).forEach((attribute) => {\n const value = node.attribs[attribute];\n if (attribute === 'class') {\n handleClassAttribute(value, node);\n }\n else if (attribute === 'style') {\n handleStyleAttribute(value, node);\n }\n else if (attribute.match(/^bind/)) {\n handleBindAttribute(value, attribute, node);\n }\n else if (attribute.match(/^catch/)) {\n handleCatchAttribute(value, attribute, node);\n }\n else if (attribute.match(/^wx:/)) {\n handleWXAttribute(value, attribute, node);\n }\n else if (attribute === 'mfConfig') {\n delete node.attribs[attribute];\n }\n else {\n handleElseAttribute(value, attribute, node);\n }\n });\n}\nasync function templateTransformer(ast, options) {\n for (let i = 0; i < ast.length; i++) {\n const node = ast[i];\n switch (node.type) {\n case 'tag':\n tagTransformer(node);\n attributeTransformer(node);\n break;\n default:\n }\n if (node.children) {\n templateTransformer(node.children, options);\n }\n }\n return ast;\n}\nexports.default = templateTransformer;\n//# sourceMappingURL=transformer.js.map","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar emptyTags = {\n area: 1,\n base: 1,\n basefont: 1,\n br: 1,\n col: 1,\n frame: 1,\n hr: 1,\n img: 1,\n input: 1,\n isindex: 1,\n link: 1,\n meta: 1,\n param: 1,\n embed: 1,\n '?xml': 1\n};\nvar ampRe = /&/g;\nvar ltRe = //g;\nvar quotRe = /\"/g;\nvar eqRe = /=/g;\nvar config = {\n disableAttribEscape: false\n};\nfunction escapeAttrib(s) {\n if (config.disableAttribEscape === true) {\n return s.toString();\n }\n if (s == null) {\n return '';\n }\n if (s.toString && typeof s.toString === 'function') {\n return s.toString().replace(ampRe, '&').replace(ltRe, '<').replace(gtRe, '>')\n .replace(quotRe, '"').replace(eqRe, '=');\n }\n else {\n return '';\n }\n}\nfunction HTMLGenerator(item, parent, eachFn) {\n if (Array.isArray(item)) {\n return item.map(function (subitem) {\n return HTMLGenerator(subitem, parent, eachFn);\n }).join('');\n }\n var orig = item;\n if (eachFn) {\n item = eachFn(item, parent);\n }\n if (typeof item !== 'undefined' && typeof item.type !== 'undefined') {\n switch (item.type) {\n case 'text':\n return item.data;\n case 'directive':\n return '<' + item.data + '>';\n case 'comment':\n return '';\n case 'style':\n case 'script':\n case 'tag':\n var result = '<' + item.name;\n if (item.attribs && Object.keys(item.attribs).length > 0) {\n result += ' ' + Object.keys(item.attribs).map(function (key) {\n return key + '=\"' + escapeAttrib(item.attribs[key]) + '\"';\n }).join(' ');\n }\n if (item.children) {\n if (!orig.render) {\n orig = parent;\n }\n result += '>' + HTMLGenerator(item.children, orig, eachFn) + (emptyTags[item.name] ? '' : '');\n }\n else {\n if (emptyTags[item.name]) {\n result += '>';\n }\n else {\n result += '>';\n }\n }\n return result;\n case 'cdata':\n return '';\n }\n }\n return item;\n}\nexports.default = HTMLGenerator;\nHTMLGenerator.configure = function (userConfig) {\n if (userConfig !== undefined) {\n for (const k in config) {\n if (userConfig[k] !== undefined) {\n config[k] = userConfig[k];\n }\n }\n }\n};\n//# sourceMappingURL=generator.js.map","\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst parser_1 = __importDefault(require(\"./parser\"));\nconst transformer_1 = __importDefault(require(\"./transformer\"));\nconst generator_1 = __importDefault(require(\"./generator\"));\nasync function default_1(sourceCode, options = {}) {\n const ast = await parser_1.default(sourceCode);\n const distAst = await transformer_1.default(ast, options);\n generator_1.default.configure({\n disableAttribEscape: true\n });\n const distCode = generator_1.default(distAst);\n return distCode;\n}\nexports.default = default_1;\n//# sourceMappingURL=index.js.map","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nfunction styleTransformer(sourceCode, options) {\n const css = sourceCode.replace(/([\\d]+)rpx/g, (m, $1) => {\n const newPx = $1.replace(/(^:)|(:$)/g, '');\n return `${newPx * 0.5}px`;\n });\n return css;\n}\nexports.default = styleTransformer;\n//# sourceMappingURL=transformer.js.map","\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst transformer_1 = __importDefault(require(\"./transformer\"));\nfunction default_1(sourceCode, options = { type: 'page' }) {\n const distCode = transformer_1.default(sourceCode, options);\n return distCode;\n}\nexports.default = default_1;\n//# sourceMappingURL=index.js.map","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst parser_1 = require(\"@babel/parser\");\nfunction default_1(sourceCode) {\n return parser_1.parse(sourceCode, {\n sourceType: 'module'\n });\n}\nexports.default = default_1;\n//# sourceMappingURL=parser.js.map","\"use strict\";\nvar __importStar = (this && this.__importStar) || function (mod) {\n if (mod && mod.__esModule) return mod;\n var result = {};\n if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];\n result[\"default\"] = mod;\n return result;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst t = __importStar(require(\"@babel/types\"));\nfunction handleProperty(path, rootPath) {\n const { node } = path;\n if (t.isObjectExpression(node.value)) {\n const propsPath = path.get('value.properties');\n const propTypePath = propsPath.filter((propPath) => t.isNodesEquivalent(propPath.node.key, t.identifier('type')))[0];\n const typeNode = propTypePath.node.value;\n let watchPropNode = t.objectProperty(node.key, t.nullLiteral());\n propsPath.forEach((propPath) => {\n const propNode = propPath.node;\n const keyName = propNode.key.name;\n const watchPropIndex = rootPath.findIndex((propPath) => t.isNodesEquivalent(propPath.node.key, t.identifier('watch')));\n switch (keyName) {\n case 'value':\n if (t.isNodesEquivalent(typeNode, t.identifier('Object'))) {\n propPath.replaceWith(t.objectProperty(t.identifier('default'), t.arrowFunctionExpression([], propNode.value)));\n }\n else if (t.isNodesEquivalent(typeNode, t.identifier('Array'))) {\n propPath.replaceWith(t.objectProperty(t.identifier('default'), t.arrowFunctionExpression([], propNode.value)));\n }\n else {\n propPath.replaceWith(t.objectProperty(t.identifier('default'), propNode.value));\n }\n break;\n case 'observer':\n if (t.isNodesEquivalent(typeNode, t.identifier('Object')) || t.isNodesEquivalent(typeNode, t.identifier('Array'))) {\n watchPropNode = t.objectProperty(node.key, t.objectExpression([\n t.objectMethod('method', t.identifier('handler'), propNode.value.params, propNode.value.body),\n t.objectProperty(t.identifier('deep'), t.booleanLiteral(true))\n ]));\n }\n else {\n watchPropNode = t.objectProperty(node.key, t.arrowFunctionExpression(propNode.value.params, propNode.value.body));\n }\n if (watchPropIndex === -1) {\n rootPath[rootPath.length - 1].insertAfter(t.objectProperty(t.identifier('watch'), t.objectExpression([watchPropNode])));\n }\n else {\n const propsPath = rootPath[watchPropIndex].get('value.properties');\n if (propsPath.length) {\n propsPath[propsPath.length - 1].insertAfter(watchPropNode);\n }\n else {\n rootPath[watchPropIndex].replaceWith(t.objectProperty(t.identifier('watch'), t.objectExpression([watchPropNode])));\n }\n }\n propPath.remove();\n break;\n }\n });\n }\n}\nfunction handleProperties(path, rootPath) {\n const { node } = path;\n const propsPath = path.get('value.properties');\n propsPath.forEach((propPath) => {\n handleProperty(propPath, rootPath);\n });\n path.replaceWith(t.objectProperty(t.identifier('props'), node.value));\n}\nfunction handleData(path) {\n const { node } = path;\n path.replaceWith(t.objectProperty(t.identifier('data'), t.arrowFunctionExpression([], node.value)));\n}\nfunction handleLifeCycles(path) {\n const { node } = path;\n const keyName = node.key.name;\n const keyNameMap = {\n ready: 'mounted',\n attached: 'beforeMount',\n detached: 'destroyed',\n behaviors: 'mixins',\n onLoad: 'created',\n onReady: 'mounted',\n onUnload: 'destroyed'\n };\n if (t.isObjectMethod(node)) {\n path.replaceWith(t.objectMethod('method', t.identifier(keyNameMap[keyName]), node.params, node.body));\n }\n else if (t.isObjectProperty(node)) {\n const { value } = node;\n if (t.isFunctionExpression(value) || t.isArrowFunctionExpression(value)) {\n path.replaceWith(t.objectMethod('method', t.identifier(keyNameMap[keyName]), value.params, value.body));\n }\n else {\n path.replaceWith(t.objectProperty(t.identifier(keyNameMap[keyName]), value));\n }\n }\n}\nfunction handleOtherProperties(path, rootPath) {\n const { node } = path;\n const rootPropsPath = rootPath.get('arguments.0.properties');\n const methodsPropIndex = rootPropsPath.findIndex((propPath) => propPath.node && t.isNodesEquivalent(propPath.node.key, t.identifier('methods')));\n if (t.isObjectMethod(node) || (t.isArrowFunctionExpression(node.value) || t.isFunctionExpression(node.value))) {\n if (methodsPropIndex === -1) {\n rootPropsPath[rootPropsPath.length - 1].insertAfter(t.objectProperty(t.identifier('methods'), t.objectExpression([node])));\n }\n else {\n const propsPath = rootPropsPath[methodsPropIndex].get('value.properties');\n if (propsPath.length) {\n propsPath[propsPath.length - 1].insertAfter(node);\n }\n else {\n rootPropsPath[methodsPropIndex].replaceWith(t.objectProperty(t.identifier('methods'), t.objectExpression([node])));\n }\n }\n path.remove();\n }\n}\nexports.default = (api, options = {}) => {\n return {\n visitor: {\n CallExpression(path) {\n const { node } = path;\n const { callee } = node;\n const rootName = options.rootName || (options.type === 'page' ? 'Page' : 'Component');\n if (options.type === 'page') {\n if (callee.name === rootName) {\n const pageArgNode = node.arguments[0];\n const propsPath = path.get('arguments.0.properties');\n propsPath.forEach((propPath) => {\n const { name } = propPath.node.key;\n switch (name) {\n case 'data':\n handleData(propPath);\n break;\n case 'onLoad':\n case 'onReady':\n case 'onUnload':\n handleLifeCycles(propPath);\n break;\n default:\n handleOtherProperties(propPath, path);\n }\n });\n path.parentPath.replaceWith(t.exportDefaultDeclaration(pageArgNode));\n }\n }\n else if (options.type === 'component') {\n if (callee.name === rootName) {\n const componentArgNode = node.arguments[0];\n const propsPath = path.get('arguments.0.properties');\n propsPath.forEach((propPath) => {\n const { name } = propPath.node.key;\n switch (name) {\n case 'properties':\n handleProperties(propPath, propsPath);\n break;\n case 'data':\n handleData(propPath);\n break;\n case 'attached':\n case 'detached':\n case 'behaviors':\n case 'ready':\n handleLifeCycles(propPath);\n break;\n default:\n handleOtherProperties(propPath, path);\n }\n });\n path.parentPath.replaceWith(t.exportDefaultDeclaration(componentArgNode));\n }\n }\n }\n }\n };\n};\n//# sourceMappingURL=structure.js.map","\"use strict\";\nvar __importStar = (this && this.__importStar) || function (mod) {\n if (mod && mod.__esModule) return mod;\n var result = {};\n if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];\n result[\"default\"] = mod;\n return result;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst t = __importStar(require(\"@babel/types\"));\nexports.default = (api, options = {}) => {\n return {\n visitor: {\n CallExpression(path) {\n const { node } = path;\n const callee = node.callee;\n if (t.isThisExpression(callee.object) && callee.property.name === 'setData') {\n if (node.arguments.length === 2) {\n const afterFunction = node.arguments[1];\n path.insertAfter(afterFunction.body.body);\n }\n const props = node.arguments[0].properties.reverse();\n props.forEach((prop) => {\n path.insertAfter(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), prop.key), prop.value));\n });\n path.remove();\n }\n },\n ThisExpression(path) {\n const parentNode = path.parentPath.node;\n if (t.isMemberExpression(parentNode) && parentNode.property.name === 'data') {\n path.parentPath.replaceWith(t.thisExpression());\n }\n }\n }\n };\n};\n//# sourceMappingURL=api.js.map","\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst traverse_1 = __importDefault(require(\"@babel/traverse\"));\nconst structure_1 = __importDefault(require(\"./structure\"));\nconst api_1 = __importDefault(require(\"./api\"));\nconst codeMods = [structure_1.default, api_1.default];\nexports.default = (ast, options) => {\n const distAst = codeMods.reduce((prev, curr) => {\n traverse_1.default(prev, curr(null, options).visitor);\n return prev;\n }, ast);\n return distAst;\n};\n//# sourceMappingURL=index.js.map","\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst generator_1 = __importDefault(require(\"@babel/generator\"));\nfunction default_1(ast) {\n return generator_1.default(ast).code;\n}\nexports.default = default_1;\n//# sourceMappingURL=generator.js.map","\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst parser_1 = __importDefault(require(\"./parser\"));\nconst transformation_1 = __importDefault(require(\"./transformation\"));\nconst generator_1 = __importDefault(require(\"./generator\"));\nfunction default_1(sourceCode, options = { type: 'page' }) {\n const ast = parser_1.default(sourceCode);\n const distAst = transformation_1.default(ast, options);\n const distCode = generator_1.default(distAst);\n return distCode;\n}\nexports.default = default_1;\n//# sourceMappingURL=index.js.map","\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst language_wxml_1 = __importDefault(require(\"./language-wxml\"));\nexports.wxmlConverter = language_wxml_1.default;\nconst language_wxss_1 = __importDefault(require(\"./language-wxss\"));\nexports.wxssConverter = language_wxss_1.default;\nconst index_1 = __importDefault(require(\"./language-js/index\"));\nexports.jsConverter = index_1.default;\nfunction default_1(sourceCodes, options) {\n}\nexports.default = default_1;\n//# sourceMappingURL=index.js.map"],"names":["Object","defineProperty","exports","value","sourceCode","Promise","resolve","reject","handler","htmlparser2_1","DomHandler","err","dom","parser","Parser","xmlMode","lowerCaseTags","recognizeSelfClosing","write","end","dynamicValue","match","tagTransformer","node","name","attributeTransformer","keys","attribs","forEach","attribute","regValue","length","dynamicClassValue","map","item","replace","restValue","reduce","accu","curr","class","trim","handleClassAttribute","styleList","split","normalStyle","dynamicStyle","finalDynamicStyle","style","property","styleValue","finalStyleValue","all","letter","toUpperCase","firstSplit","secondSplit","concat","part","index","JSON","stringify","transferFinalStyleValue","m","$1","push","join","handleStyleAttribute","eventName","indexOf","substr","handleBindAttribute","handleCatchAttribute","forItem","forIndex","forContent","handleWXAttribute","handleElseAttribute","async","templateTransformer","ast","options","i","type","children","emptyTags","area","base","basefont","br","col","frame","hr","img","input","isindex","link","meta","param","embed","?xml","ampRe","ltRe","gtRe","quotRe","eqRe","config","disableAttribEscape","HTMLGenerator","parent","eachFn","Array","isArray","subitem","orig","data","result","key","s","toString","render","configure","userConfig","undefined","k","__importDefault","this","mod","__esModule","default","parser_1","require$$0","transformer_1","require$$1","generator_1","require$$2","distAst","parse","sourceType","__importStar","hasOwnProperty","call","t","handleProperties","path","rootPath","get","propPath","isObjectExpression","propsPath","typeNode","filter","isNodesEquivalent","identifier","watchPropNode","objectProperty","nullLiteral","propNode","keyName","watchPropIndex","findIndex","replaceWith","arrowFunctionExpression","objectExpression","objectMethod","params","body","booleanLiteral","insertAfter","remove","handleProperty","handleData","handleLifeCycles","keyNameMap","ready","attached","detached","behaviors","onLoad","onReady","onUnload","isObjectMethod","isObjectProperty","isFunctionExpression","isArrowFunctionExpression","handleOtherProperties","rootPropsPath","methodsPropIndex","api","visitor","[object Object]","callee","rootName","pageArgNode","arguments","parentPath","exportDefaultDeclaration","componentArgNode","isThisExpression","object","afterFunction","properties","reverse","prop","assignmentExpression","memberExpression","thisExpression","parentNode","isMemberExpression","traverse_1","structure_1","api_1","codeMods","prev","code","transformation_1","language_wxml_1","language_wxss_1","index_1","sourceCodes"],"mappings":"mgCACAA,OAAOC,eAAeC,EAAS,aAAc,CAAEC,OAAO,IAmBtDD,UAjBA,SAAeE,GACX,OAAO,IAAIC,QAAQ,CAACC,EAASC,KACzB,MAAMC,EAAU,IAAIC,EAAcC,WAAW,CAACC,EAAKC,KAC3CD,GACAJ,EAAOI,GAEXL,EAAQM,KAENC,EAAS,IAAIJ,EAAcK,OAAON,EAAS,CAC7CO,SAAS,EACTC,eAAe,EACfC,sBAAsB,IAE1BJ,EAA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EAAgBU,GAChCrI,cAAsBwN,EAAQzF,QAG9B/H,UAFA,SAAmByN,EAAa1I"} -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | roots: ['/src', '/__test__'], 3 | transform: { 4 | '^.+\\.ts$': 'ts-jest' 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@espkg/mina2vue", 3 | "version": "0.4.5", 4 | "description": "Convert native wxml, wxss eg. to .vue files", 5 | "main": "dist/yu_gong.js", 6 | "typings": "dist/@types/index.d.ts", 7 | "directories": { 8 | "src": "dist" 9 | }, 10 | "scripts": { 11 | "dev": "jest --coverage --watchAll", 12 | "start": "tsc -w & NODE_ENV=development rollup -c rollup.config.ts -w", 13 | "build": "tsc && tsc --module commonjs --outDir dist/lib && NODE_ENV=production rollup -c rollup.config.ts", 14 | "test": "jest --coverage" 15 | }, 16 | "repository": { 17 | "type": "git", 18 | "url": "git+https://github.com/espkg/mina2vue.git" 19 | }, 20 | "keywords": [], 21 | "author": "", 22 | "license": "MIT", 23 | "bugs": { 24 | "url": "https://github.com/espkg/mina2vue/issues" 25 | }, 26 | "homepage": "https://github.com/espkg/mina2vue#readme", 27 | "dependencies": { 28 | "@babel/generator": "^7.8.3", 29 | "@babel/parser": "^7.8.3", 30 | "@babel/traverse": "^7.8.3", 31 | "@babel/types": "^7.8.3", 32 | "htmlparser2": "^4.0.0" 33 | }, 34 | "devDependencies": { 35 | "@types/jest": "^24.9.0", 36 | "@typescript-eslint/eslint-plugin": "^2.17.0", 37 | "@typescript-eslint/parser": "^2.17.0", 38 | "babel-eslint": "^10.0.3", 39 | "eslint": "^6.8.0", 40 | "eslint-config-standard": "^14.1.0", 41 | "eslint-plugin-import": "^2.20.0", 42 | "eslint-plugin-jest": "^23.6.0", 43 | "eslint-plugin-node": "^11.0.0", 44 | "eslint-plugin-promise": "^4.2.1", 45 | "eslint-plugin-standard": "^4.0.1", 46 | "jest": "^24.9.0", 47 | "rollup": "^1.29.0", 48 | "rollup-plugin-commonjs": "^10.1.0", 49 | "rollup-plugin-terser": "^5.2.0", 50 | "ts-jest": "^24.3.0", 51 | "typescript": "^3.7.5" 52 | }, 53 | "files": [ 54 | "dist/lib", 55 | "dist/@types", 56 | "dist/yu_gong.js", 57 | "dist/yu_gong.js.map" 58 | ] 59 | } 60 | -------------------------------------------------------------------------------- /rollup.config.ts: -------------------------------------------------------------------------------- 1 | import commonjs from 'rollup-plugin-commonjs' 2 | import { terser } from 'rollup-plugin-terser' 3 | 4 | const { NODE_ENV } = process.env 5 | 6 | export default { 7 | input: 'dist/lib/index.js', 8 | output: { 9 | name: 'YG', 10 | file: './dist/yu_gong.js', 11 | format: 'umd', 12 | exports: 'named', 13 | sourcemap: true 14 | }, 15 | plugins: [ 16 | commonjs(), 17 | NODE_ENV === 'production' && terser() 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /src/@types/index.d.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espkg/mina2vue/07ebd294282c69da5a5e248e0e4e9c8b63cbcdee/src/@types/index.d.ts -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import wxmlConverter from './language-wxml' 2 | import wxssConverter from './language-wxss' 3 | import jsConverter from './language-js/index' 4 | import vueGenerator from './language-vue/generator' 5 | 6 | export { 7 | jsConverter, 8 | wxmlConverter, 9 | wxssConverter, 10 | vueGenerator 11 | } 12 | 13 | // export default function (sourceCodes : string, options : any) { 14 | 15 | // } 16 | -------------------------------------------------------------------------------- /src/language-js/generator.ts: -------------------------------------------------------------------------------- 1 | import generator from '@babel/generator' 2 | 3 | export default function (ast : babel.types.Node) : string { 4 | return generator(ast).code 5 | } 6 | -------------------------------------------------------------------------------- /src/language-js/index.ts: -------------------------------------------------------------------------------- 1 | import parser from './parser' 2 | import transformer from './transformation' 3 | import generator from './generator' 4 | 5 | // TODO: 默认 options 6 | export default function (sourceCode : string, options : any = { type: 'page' }) : string { 7 | const ast : babel.types.File = parser(sourceCode) 8 | 9 | const distAst = transformer(ast, options) 10 | 11 | const distCode : string = generator(distAst) 12 | 13 | return distCode 14 | } 15 | -------------------------------------------------------------------------------- /src/language-js/parser.ts: -------------------------------------------------------------------------------- 1 | import { parse } from '@babel/parser' 2 | 3 | export default function (sourceCode : string) : babel.types.File { 4 | return parse(sourceCode, { 5 | sourceType: 'module' 6 | }) 7 | } 8 | -------------------------------------------------------------------------------- /src/language-js/transformation/api.ts: -------------------------------------------------------------------------------- 1 | import * as t from '@babel/types' 2 | 3 | export default (api : any, options : any = {}) : babel.PluginObj => { 4 | return { 5 | visitor: { 6 | CallExpression (path : babel.NodePath) { 7 | const { node } : { node : t.CallExpression } = path 8 | const callee = node.callee as t.MemberExpression 9 | 10 | // this.setData -> this.x = xxx 11 | if (t.isThisExpression(callee.object) && callee.property.name === 'setData') { 12 | // 如果 setData 有第二个参数 13 | if (node.arguments.length === 2) { 14 | const afterFunction = node.arguments[1] as t.FunctionExpression 15 | path.insertAfter(afterFunction.body.body) 16 | } 17 | 18 | const props = ((node.arguments[0] as t.ObjectExpression).properties as t.ObjectProperty[]).reverse() // 倒序插入 19 | props.forEach((prop : t.ObjectProperty) => { 20 | path.insertAfter( 21 | t.assignmentExpression('=', t.memberExpression(t.thisExpression(), prop.key), (prop.value as t.Identifier)) 22 | ) 23 | }) 24 | 25 | path.remove() 26 | } 27 | }, 28 | ThisExpression (path) { 29 | // this.data.foo -> this.foo 30 | const parentNode = path.parentPath.node 31 | if (t.isMemberExpression(parentNode) && parentNode.property.name === 'data') { 32 | path.parentPath.replaceWith(t.thisExpression()) 33 | } 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/language-js/transformation/index.ts: -------------------------------------------------------------------------------- 1 | import traverse from '@babel/traverse' 2 | import structureTransformer from './structure' 3 | import apiTransformer from './api' 4 | 5 | const codeMods : Array = [structureTransformer, apiTransformer] 6 | 7 | export default (ast : babel.types.File, options : any) : babel.types.File => { 8 | // TODO: 更优雅的合并 plugins 9 | const distAst : any = codeMods.reduce((prev, curr) : any => { 10 | traverse(prev, curr(null, options).visitor) 11 | return prev 12 | }, ast) 13 | return distAst 14 | } 15 | -------------------------------------------------------------------------------- /src/language-js/transformation/structure.ts: -------------------------------------------------------------------------------- 1 | import * as t from '@babel/types' 2 | 3 | function handleProperty (path : babel.NodePath, rootPath : babel.NodePath[]) { 4 | const { node } : { node : t.ObjectProperty } = path 5 | 6 | if (t.isObjectExpression(node.value)) { 7 | const propsPath = (path.get('value.properties') as babel.NodePath[]) 8 | const propTypePath = propsPath.filter((propPath) => t.isNodesEquivalent(propPath.node.key, t.identifier('type')))[0] 9 | const typeNode = propTypePath.node.value 10 | let watchPropNode : t.ObjectProperty = t.objectProperty(node.key, t.nullLiteral()) 11 | 12 | propsPath.forEach((propPath) => { 13 | const propNode = propPath.node 14 | const keyName = propNode.key.name 15 | const watchPropIndex = rootPath.findIndex((propPath) => t.isNodesEquivalent(propPath.node.key, t.identifier('watch'))) 16 | 17 | switch (keyName) { 18 | case 'value': 19 | if (t.isNodesEquivalent(typeNode, t.identifier('Object'))) { 20 | propPath.replaceWith( 21 | t.objectProperty( 22 | t.identifier('default'), 23 | t.arrowFunctionExpression([], (propNode.value as t.ObjectExpression)) 24 | ) 25 | ) 26 | } else if (t.isNodesEquivalent(typeNode, t.identifier('Array'))) { 27 | propPath.replaceWith( 28 | t.objectProperty( 29 | t.identifier('default'), 30 | t.arrowFunctionExpression([], (propNode.value as t.ArrayExpression)) 31 | ) 32 | ) 33 | } else { 34 | propPath.replaceWith( 35 | t.objectProperty( 36 | t.identifier('default'), 37 | propNode.value 38 | ) 39 | ) 40 | } 41 | break 42 | case 'observer': 43 | if (t.isNodesEquivalent(typeNode, t.identifier('Object')) || t.isNodesEquivalent(typeNode, t.identifier('Array'))) { 44 | // 引用类型换成深度监听 45 | watchPropNode = t.objectProperty( 46 | node.key, 47 | t.objectExpression([ 48 | t.objectMethod('method', t.identifier('handler'), (propNode.value as t.FunctionExpression).params, (propNode.value as t.FunctionExpression).body), 49 | t.objectProperty(t.identifier('deep'), t.booleanLiteral(true)) 50 | ]) 51 | ) 52 | } else { 53 | watchPropNode = t.objectProperty( 54 | node.key, 55 | t.arrowFunctionExpression((propNode.value as t.FunctionExpression).params, (propNode.value as t.FunctionExpression).body) 56 | ) 57 | } 58 | 59 | if (watchPropIndex === -1) { // 如果没有 watch 属性则添加一个 60 | rootPath[rootPath.length - 1].insertAfter( 61 | t.objectProperty( 62 | t.identifier('watch'), 63 | t.objectExpression([watchPropNode]) 64 | ) 65 | ) 66 | } else { 67 | // eslint-disable-next-line 68 | const propsPath = (rootPath[watchPropIndex].get('value.properties') as babel.NodePath[]) 69 | if (propsPath.length) { 70 | propsPath[propsPath.length - 1].insertAfter(watchPropNode) 71 | } else { // watch 属性为空对象 72 | rootPath[watchPropIndex].replaceWith( 73 | t.objectProperty( 74 | t.identifier('watch'), 75 | t.objectExpression([watchPropNode]) 76 | ) 77 | ) 78 | } 79 | } 80 | 81 | propPath.remove() 82 | break 83 | } 84 | }) 85 | } 86 | } 87 | 88 | function handleProperties (path : babel.NodePath, rootPath : babel.NodePath[]) { 89 | const { node } : { node : t.ObjectProperty } = path 90 | const propsPath = (path.get('value.properties') as babel.NodePath[]) 91 | 92 | propsPath.forEach((propPath) => { 93 | handleProperty(propPath, rootPath) 94 | }) 95 | 96 | path.replaceWith( 97 | t.objectProperty( 98 | t.identifier('props'), 99 | node.value 100 | ) 101 | ) 102 | } 103 | 104 | function handleData (path : babel.NodePath) { 105 | const { node } : { node : t.ObjectProperty } = path 106 | 107 | path.replaceWith( 108 | t.objectProperty( 109 | t.identifier('data'), 110 | t.arrowFunctionExpression([], (node.value as t.ObjectExpression)) 111 | ) 112 | ) 113 | } 114 | 115 | function handleLifeCycles (path : babel.NodePath) { 116 | const { node } : { node : t.ObjectProperty | t.ObjectMethod } = path 117 | const keyName : string = node.key.name 118 | const keyNameMap : { [key : string] : string } = { 119 | ready: 'mounted', 120 | attached: 'beforeMount', 121 | detached: 'destroyed', 122 | behaviors: 'mixins', 123 | onLoad: 'created', 124 | onReady: 'mounted', 125 | onUnload: 'destroyed' 126 | } 127 | 128 | if (t.isObjectMethod(node)) { 129 | path.replaceWith( 130 | t.objectMethod('method', t.identifier(keyNameMap[keyName]), node.params, node.body) 131 | ) 132 | } else if (t.isObjectProperty(node)) { 133 | const { value } = (node as t.ObjectProperty) 134 | if (t.isFunctionExpression(value) || t.isArrowFunctionExpression(value)) { 135 | path.replaceWith( 136 | t.objectMethod('method', t.identifier(keyNameMap[keyName]), value.params, 137 | (value as t.FunctionExpression).body 138 | ) 139 | ) 140 | } else { 141 | path.replaceWith( 142 | t.objectProperty(t.identifier(keyNameMap[keyName]), value) 143 | ) 144 | } 145 | } 146 | } 147 | 148 | function handleOtherProperties (path : babel.NodePath, rootPath : babel.NodePath) { 149 | const { node } : { node : t.ObjectProperty | t.ObjectMethod } = path 150 | const rootPropsPath = (rootPath.get('arguments.0.properties') as babel.NodePath[]) 151 | const methodsPropIndex = rootPropsPath.findIndex((propPath) => propPath.node && t.isNodesEquivalent(propPath.node.key, t.identifier('methods'))) 152 | 153 | if (t.isObjectMethod(node) || (t.isArrowFunctionExpression(node.value) || t.isFunctionExpression(node.value))) { 154 | if (methodsPropIndex === -1) { // 如果没有 methods 属性则添加一个 155 | rootPropsPath[rootPropsPath.length - 1].insertAfter( 156 | t.objectProperty( 157 | t.identifier('methods'), 158 | t.objectExpression([node]) 159 | ) 160 | ) 161 | } else { 162 | const propsPath = (rootPropsPath[methodsPropIndex].get('value.properties') as babel.NodePath[]) 163 | if (propsPath.length) { 164 | propsPath[propsPath.length - 1].insertAfter(node) 165 | } else { // methods 属性为空对象 166 | rootPropsPath[methodsPropIndex].replaceWith( 167 | t.objectProperty(t.identifier('methods'), t.objectExpression([node])) 168 | ) 169 | } 170 | } 171 | 172 | path.remove() 173 | } 174 | } 175 | 176 | export default (api : any, options : any = {}) : babel.PluginObj => { 177 | return { 178 | visitor: { 179 | CallExpression (path : babel.NodePath) { 180 | const { node } : { node : t.CallExpression } = path 181 | const { callee } = node 182 | 183 | // TODO: options.type 改为枚举 184 | const rootName : string = options.rootName || (options.type === 'page' ? 'Page' : 'Component') 185 | 186 | if (options.type === 'page') { 187 | if ((callee as t.V8IntrinsicIdentifier).name === rootName) { 188 | // pageArgNode 页面顶层属性 189 | const pageArgNode : t.ObjectExpression = (node.arguments[0] as t.ObjectExpression) 190 | const propsPath = (path.get('arguments.0.properties') as babel.NodePath[]) 191 | 192 | // 处理页面顶层属性 193 | propsPath.forEach((propPath) => { 194 | const { name } = propPath.node.key 195 | 196 | switch (name) { 197 | case 'data': 198 | handleData(propPath) 199 | break 200 | // case 'watch': 201 | // case 'observers': 202 | // // 平移进 watch 属性,优先级不高 203 | // break 204 | case 'onLoad': 205 | case 'onReady': 206 | case 'onUnload': 207 | handleLifeCycles(propPath) 208 | break 209 | default: 210 | handleOtherProperties(propPath, path) 211 | } 212 | }) 213 | 214 | path.parentPath.replaceWith( 215 | t.exportDefaultDeclaration(pageArgNode) 216 | ) 217 | } 218 | } else if (options.type === 'component') { 219 | if ((callee as t.V8IntrinsicIdentifier).name === rootName) { 220 | // componentArgNode 组件顶层属性 221 | const componentArgNode : t.ObjectExpression = (node.arguments[0] as t.ObjectExpression) 222 | const propsPath = (path.get('arguments.0.properties') as babel.NodePath[]) 223 | 224 | // 处理组件顶层属性 225 | propsPath.forEach((propPath) => { 226 | const { name } = propPath.node.key 227 | 228 | switch (name) { 229 | case 'properties': 230 | handleProperties(propPath, propsPath) 231 | break 232 | case 'data': 233 | handleData(propPath) 234 | break 235 | // case 'watch': 236 | // case 'observers': 237 | // // 平移进 watch 属性,优先级不高 238 | // break 239 | case 'attached': 240 | case 'detached': 241 | case 'behaviors': 242 | case 'ready': 243 | handleLifeCycles(propPath) 244 | break 245 | default: 246 | handleOtherProperties(propPath, path) 247 | } 248 | }) 249 | 250 | path.parentPath.replaceWith( 251 | t.exportDefaultDeclaration(componentArgNode) 252 | ) 253 | } 254 | } 255 | } 256 | } 257 | } 258 | } 259 | -------------------------------------------------------------------------------- /src/language-vue/generator.ts: -------------------------------------------------------------------------------- 1 | export default function vueGenerator (template = '', style = '', scripts = '') { 2 | let result = '' 3 | if (template.length) { 4 | result += `` 7 | } 8 | if (scripts.length) { 9 | result += ` 10 | ` 11 | result += `` 14 | } 15 | if (style.length) { 16 | result += ` 17 | ` 18 | result += `` 21 | } 22 | 23 | return result 24 | } 25 | -------------------------------------------------------------------------------- /src/language-wxml/generator.ts: -------------------------------------------------------------------------------- 1 | var emptyTags : any = { 2 | area: 1, 3 | base: 1, 4 | basefont: 1, 5 | br: 1, 6 | col: 1, 7 | frame: 1, 8 | hr: 1, 9 | img: 1, 10 | input: 1, 11 | isindex: 1, 12 | link: 1, 13 | meta: 1, 14 | param: 1, 15 | embed: 1, 16 | '?xml': 1 17 | } 18 | 19 | var ampRe = /&/g 20 | // var looseAmpRe = /&([^a-z#]|#(?:[^0-9x]|x(?:[^0-9a-f]|$)|$)|$)/gi 21 | var ltRe = //g 23 | var quotRe = /"/g 24 | var eqRe = /=/g 25 | 26 | var config : any = { 27 | disableAttribEscape: false 28 | } 29 | 30 | function escapeAttrib (s : any) { 31 | if (config.disableAttribEscape === true) { return s.toString() } 32 | 33 | // null or undefined 34 | if (s == null) { return '' } 35 | if (s.toString && typeof s.toString === 'function') { 36 | // Escaping '=' defangs many UTF-7 and SGML short-tag attacks. 37 | return s.toString().replace(ampRe, '&').replace(ltRe, '<').replace(gtRe, '>') 38 | .replace(quotRe, '"').replace(eqRe, '=') 39 | } else { 40 | return '' 41 | } 42 | } 43 | 44 | export default function HTMLGenerator (item : any, parent ?: any, eachFn ?: any) : any { 45 | // apply recursively to arrays 46 | if (Array.isArray(item)) { 47 | return item.map(function (subitem) { 48 | // parent, not item: the parent of an array item is not the array, 49 | // but rather the element that contained the array 50 | return HTMLGenerator(subitem, parent, eachFn) 51 | }).join('') 52 | } 53 | var orig = item 54 | if (eachFn) { 55 | item = eachFn(item, parent) 56 | } 57 | if (typeof item !== 'undefined' && typeof item.type !== 'undefined') { 58 | switch (item.type) { 59 | case 'text': 60 | return item.data 61 | case 'directive': 62 | return '<' + item.data + '>' 63 | case 'comment': 64 | return '' 65 | case 'style': 66 | case 'script': 67 | case 'tag': 68 | var result = '<' + item.name 69 | if (item.attribs && Object.keys(item.attribs).length > 0) { 70 | result += ' ' + Object.keys(item.attribs).map(function (key) { 71 | return key + '="' + escapeAttrib(item.attribs[key]) + '"' 72 | }).join(' ') 73 | } 74 | if (item.children) { 75 | // parent becomes the current element 76 | // check if the current item (before any eachFns are run) - is a renderable 77 | if (!orig.render) { 78 | orig = parent 79 | } 80 | result += '>' + HTMLGenerator(item.children, orig, eachFn) + (emptyTags[item.name] ? '' : '') 81 | } else { 82 | if (emptyTags[item.name]) { 83 | result += '>' 84 | } else { 85 | result += '>' 86 | } 87 | } 88 | return result 89 | case 'cdata': 90 | return '' 91 | } 92 | } 93 | return item 94 | } 95 | 96 | HTMLGenerator.configure = function (userConfig : any) { 97 | if (userConfig !== undefined) { 98 | for (const k in config) { 99 | if (userConfig[k] !== undefined) { 100 | config[k] = userConfig[k] 101 | } 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/language-wxml/index.ts: -------------------------------------------------------------------------------- 1 | import parser from './parser' 2 | import transformer from './transformer' 3 | import generator from './generator' 4 | 5 | // TODO: 默认 options 6 | export default async function (sourceCode : string, options : any = { }) { 7 | const ast = await parser(sourceCode) 8 | 9 | const distAst = await transformer(ast, options) 10 | 11 | generator.configure({ 12 | disableAttribEscape: true 13 | }) 14 | const distCode : string = generator(distAst) 15 | 16 | // Undo the hacky fix from parser 17 | return distCode.replace(/<>/g, (m) => { 18 | return `<` 19 | }) 20 | } 21 | -------------------------------------------------------------------------------- /src/language-wxml/parser.ts: -------------------------------------------------------------------------------- 1 | import { DomHandler, Parser } from 'htmlparser2' 2 | 3 | export default function parse (sourceCode : string) { 4 | return new Promise((resolve, reject) => { 5 | const handler = new DomHandler((err, dom) => { 6 | if (err) { 7 | reject(err) 8 | } 9 | 10 | resolve(dom) 11 | }) 12 | 13 | const parser = new Parser(handler, { 14 | xmlMode: true, 15 | lowerCaseTags: false, 16 | recognizeSelfClosing: true 17 | }) 18 | 19 | // When change < to <>, htmlparser2 reads as part of same text node. 20 | const hackyFix = sourceCode.replace(/(>[^<]*)<(.*<)/g, (m, $1, $2) => { 21 | return `${$1}<>${$2}` 22 | }) 23 | 24 | parser.write(hackyFix) 25 | parser.end() 26 | }) 27 | } 28 | -------------------------------------------------------------------------------- /src/language-wxml/transformer.ts: -------------------------------------------------------------------------------- 1 | function dynamicValue (value : any) { 2 | if (!value) return [] 3 | return value.match(/{{(.*?)}}/g) 4 | } 5 | 6 | function tagTransformer (node : any) { 7 | switch (node.name) { 8 | case 'view': 9 | node.name = 'div' 10 | break 11 | 12 | case 'text': 13 | node.name = 'span' 14 | break 15 | 16 | case 'block': 17 | node.name = 'template' 18 | break 19 | 20 | case 'image': 21 | node.name = 'img' 22 | break 23 | 24 | case 'mf-page': 25 | node.name = 'div' 26 | break 27 | 28 | default: 29 | } 30 | } 31 | 32 | function handleClassAttribute (value : any, node : any) { 33 | const regValue = dynamicValue(value) 34 | 35 | if (regValue && regValue.length) { 36 | const dynamicClassValue = regValue.map((item : any) => item.replace(/{{(.*?)}}/, '$1')) 37 | node.attribs[':class'] = `[${dynamicClassValue}]` 38 | const restValue = regValue.reduce((accu : any, curr : any) => { 39 | return accu.replace(curr, '') 40 | }, value) 41 | node.attribs.class = restValue.trim() 42 | } 43 | } 44 | 45 | function handleStyleAttribute (value : any, node : any) { 46 | const styleList = value.split(';') // 拆分成每条 style 47 | const normalStyle : any = [] 48 | const dynamicStyle : any = {} 49 | let finalDynamicStyle = '' 50 | 51 | styleList.forEach((style : any) => { 52 | const regValue = dynamicValue(style) 53 | 54 | if (regValue && regValue.length) { 55 | let [property, styleValue] = style.split(':') 56 | let finalStyleValue = '' 57 | 58 | // 属性切换成驼峰格式 59 | property = property.replace(/-(\w)/g, (all : any, letter : any) => letter.toUpperCase()).trim() 60 | 61 | // 处理样式的格式 62 | const firstSplit = styleValue.split('{{') 63 | let secondSplit : any = [] 64 | firstSplit.forEach((item : any) => { 65 | secondSplit = secondSplit.concat(item.split('}}')) 66 | }) 67 | secondSplit.forEach((part : any, index : any) => { 68 | if (!part) return 69 | if (finalStyleValue.length) finalStyleValue += (index > 0 && '+') || '' 70 | finalStyleValue += (index % 2 ? part : JSON.stringify(part.trim())) 71 | }) 72 | const transferFinalStyleValue = finalStyleValue.replace(/([\d]+)rpx/g, (m, $1) => { 73 | const newPx = $1.replace(/(^:)|(:$)/g, '') 74 | return `${newPx * 0.5}px` 75 | }) 76 | dynamicStyle[property] = transferFinalStyleValue 77 | 78 | // dynamicStyle[property] = finalStyleValue 79 | } else { 80 | // 静态 style 直接保存 81 | const css = style.trim() 82 | const transferFinalStyleValue = css.replace( 83 | /([\d]+)rpx/g, 84 | (m : any, $1 : any) => { 85 | const newPx = $1.replace(/(^:)|(:$)/g, '') 86 | return `${newPx * 0.5}px` 87 | } 88 | ) 89 | normalStyle.push(transferFinalStyleValue) 90 | } 91 | }) 92 | 93 | node.attribs.style = normalStyle.join(';') 94 | // 拼接成字符串 95 | if (Object.keys(dynamicStyle).length) { 96 | finalDynamicStyle = '{ ' 97 | Object.keys(dynamicStyle).forEach((property) => { 98 | const value = dynamicStyle[property] 99 | finalDynamicStyle += property 100 | finalDynamicStyle += ': ' 101 | finalDynamicStyle += value.replace(/"/g, "'") 102 | finalDynamicStyle += ';' 103 | }) 104 | finalDynamicStyle += ' }' 105 | node.attribs[':style'] = finalDynamicStyle 106 | } 107 | } 108 | 109 | function handleBindAttribute (value : any, attribute : any, node : any) { 110 | let eventName = '' 111 | 112 | if (attribute.indexOf(':') !== -1) { 113 | eventName = attribute.split(':')[1] 114 | } else { 115 | eventName = attribute.substr(4) 116 | } 117 | 118 | if (eventName === 'tap') eventName = 'click' 119 | 120 | node.attribs[`@${eventName}`] = `${value}($event)` 121 | delete node.attribs[attribute] 122 | } 123 | 124 | function handleCatchAttribute (value : any, attribute : any, node : any) { 125 | let eventName = '' 126 | 127 | if (attribute.indexOf(':') !== -1) { 128 | eventName = attribute.split(':')[1] 129 | } else { 130 | eventName = attribute.substr(5) 131 | } 132 | 133 | if (eventName === 'tap') eventName = 'click' 134 | 135 | node.attribs[`@${eventName}.stop`] = value 136 | delete node.attribs[attribute] 137 | } 138 | 139 | function handleWXAttribute (value : any, attribute : any, node : any) { 140 | const attrName = attribute.split(':')[1] 141 | 142 | switch (attrName) { 143 | case 'if': 144 | node.attribs['v-if'] = value.replace(/{{(.*?)}}/, '$1').trim() 145 | delete node.attribs[attribute] 146 | break 147 | 148 | case 'else': 149 | node.attribs['v-else'] = '' // TODO: 此处会生成 v-else="" 需要修改 template generator 150 | delete node.attribs[attribute] 151 | break 152 | 153 | case 'elif': 154 | node.attribs['v-else-if'] = value.replace(/{{(.*?)}}/, '$1').trim() 155 | delete node.attribs[attribute] 156 | break 157 | 158 | case 'key': 159 | node.attribs[':key'] = value.replace(/{{(.*?)}}/, '$1').trim() 160 | delete node.attribs[attribute] 161 | break 162 | 163 | case 'for': 164 | /* eslint-disable */ 165 | const forItem = node.attribs['wx:for-item'] 166 | const forIndex = node.attribs['wx:for-index'] 167 | const forContent = value.replace(/{{(.*?)}}/, '$1').trim() 168 | /* eslint-enable */ 169 | node.attribs['v-for'] = `(${forItem || 'item'}, ${forIndex || 'index'}) in ${forContent}` 170 | delete node.attribs['wx:for-item'] 171 | delete node.attribs['wx:for-index'] 172 | delete node.attribs[attribute] 173 | break 174 | } 175 | } 176 | 177 | function handleElseAttribute (value : any, attribute : any, node : any) { 178 | if (dynamicValue(value) && dynamicValue(value).length) { 179 | node.attribs[`:${attribute}`] = value.replace(/{{(.*?)}}/, '$1').trim() 180 | delete node.attribs[attribute] 181 | } 182 | } 183 | 184 | function attributeTransformer (node : any) { 185 | Object.keys(node.attribs).forEach((attribute) => { 186 | const value = node.attribs[attribute] 187 | 188 | if (attribute === 'class') { 189 | handleClassAttribute(value, node) 190 | } else if (attribute === 'style') { 191 | handleStyleAttribute(value, node) 192 | } else if (attribute.match(/^bind/)) { 193 | handleBindAttribute(value, attribute, node) 194 | } else if (attribute.match(/^catch/)) { 195 | handleCatchAttribute(value, attribute, node) 196 | } else if (attribute.match(/^wx:/)) { 197 | handleWXAttribute(value, attribute, node) 198 | } else if (attribute === 'mfConfig') { 199 | delete node.attribs[attribute] 200 | } else { 201 | handleElseAttribute(value, attribute, node) 202 | } 203 | }) 204 | } 205 | 206 | export default async function templateTransformer (ast : any, options : any) { 207 | for (let i = 0; i < ast.length; i++) { 208 | const node = ast[i] 209 | 210 | switch (node.type) { 211 | case 'tag': 212 | tagTransformer(node) 213 | attributeTransformer(node) 214 | break 215 | 216 | default: 217 | } 218 | 219 | if (node.children) { 220 | templateTransformer(node.children, options) 221 | } 222 | } 223 | 224 | return ast 225 | } 226 | -------------------------------------------------------------------------------- /src/language-wxss/index.ts: -------------------------------------------------------------------------------- 1 | import transformer from './transformer' 2 | 3 | // TODO: 默认 options 4 | export default function (sourceCode : string, options : any = { type: 'page' }) : string { 5 | const distCode = transformer(sourceCode, options) 6 | 7 | return distCode 8 | } 9 | -------------------------------------------------------------------------------- /src/language-wxss/transformer.ts: -------------------------------------------------------------------------------- 1 | export default function styleTransformer (sourceCode : string, options : any) { 2 | const css = sourceCode.replace(/([\d]+\s*)r(px|em)/g, (m, $1, $2) => { 3 | 4 | const newPx = $1.replace(/(^:)|(:$)/g, '') 5 | return `${newPx * 0.5}${$2}`; 6 | }) 7 | return css 8 | } 9 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Basic Options */ 4 | // "incremental": true, /* Enable incremental compilation */ 5 | "target": "ESNext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ 6 | "module": "ESNext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ 7 | "lib": [ "ESNext", "DOM" ], /* Specify library files to be included in the compilation. */ 8 | // "allowJs": true, /* Allow javascript files to be compiled. */ 9 | // "checkJs": true, /* Report errors in .js files. */ 10 | // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ 11 | "declaration": true, /* Generates corresponding '.d.ts' file. */ 12 | "declarationDir": "dist/@types", 13 | // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ 14 | "sourceMap": true, /* Generates corresponding '.map' file. */ 15 | // "outFile": "./", /* Concatenate and emit output to single file. */ 16 | "outDir": "dist/es", /* Redirect output structure to the directory. */ 17 | // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ 18 | // "composite": true, /* Enable project compilation */ 19 | // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ 20 | "removeComments": true, /* Do not emit comments to output. */ 21 | // "noEmit": true, /* Do not emit outputs. */ 22 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */ 23 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ 24 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ 25 | 26 | /* Strict Type-Checking Options */ 27 | "strict": true, /* Enable all strict type-checking options. */ 28 | "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ 29 | // "strictNullChecks": true, /* Enable strict null checks. */ 30 | // "strictFunctionTypes": true, /* Enable strict checking of function types. */ 31 | // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ 32 | // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ 33 | // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ 34 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ 35 | 36 | /* Additional Checks */ 37 | // "noUnusedLocals": true, /* Report errors on unused locals. */ 38 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 39 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 40 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 41 | 42 | /* Module Resolution Options */ 43 | "moduleResolution": "Node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ 44 | // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ 45 | // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ 46 | // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ 47 | // "typeRoots": [], /* List of folders to include type definitions from. */ 48 | // "types": [], /* Type declaration files to be included in compilation. */ 49 | "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ 50 | "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ 51 | // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ 52 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 53 | 54 | /* Source Map Options */ 55 | // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ 56 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 57 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ 58 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ 59 | 60 | /* Experimental Options */ 61 | // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ 62 | // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ 63 | 64 | /* Advanced Options */ 65 | "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ 66 | }, 67 | "include": [ "src/**/*" ], 68 | "exclude": ["node_modules", "**/*.spec.ts"], 69 | } 70 | --------------------------------------------------------------------------------