From 907895a5db48fc64b612fe5a04f21a4419594e80 Mon Sep 17 00:00:00 2001 From: qiang Date: Thu, 10 Jun 2021 15:34:14 +0800 Subject: [PATCH] fix(mp): $mp.component -> $scope --- .../__tests__/compiler-mp-alipay.spec.js | 4 ++-- .../__tests__/compiler-mp-baidu.spec.js | 4 ++-- .../__tests__/compiler-mp-weixin.spec.js | 6 +++--- packages/uni-template-compiler/lib/script/traverse/index.js | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js b/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js index 355f816b5..26ed0cf0f 100644 --- a/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js @@ -115,7 +115,7 @@ describe('mp:compiler-mp-alipay', () => { assertCodegen( '', '', - 'with(this){if($mp.component.props.scopedSlotsCompiler==="augmented"){const $root=$mp.data.$root;$setScopedSlotsParams("default",{"item":item})}}', + 'with(this){if($scope.props.scopedSlotsCompiler==="augmented"){const $root=$mp.data.$root;$setScopedSlotsParams("default",{"item":item})}}', { scopedSlotsCompiler: 'auto' } @@ -123,7 +123,7 @@ describe('mp:compiler-mp-alipay', () => { assertCodegen( '', '', - 'with(this){if($mp.component.props.scopedSlotsCompiler==="augmented"){const $root=$mp.data.$root;$setScopedSlotsParams("default",object)}}', + 'with(this){if($scope.props.scopedSlotsCompiler==="augmented"){const $root=$mp.data.$root;$setScopedSlotsParams("default",object)}}', { scopedSlotsCompiler: 'auto' } diff --git a/packages/uni-template-compiler/__tests__/compiler-mp-baidu.spec.js b/packages/uni-template-compiler/__tests__/compiler-mp-baidu.spec.js index d2c9c7cd0..398051d31 100644 --- a/packages/uni-template-compiler/__tests__/compiler-mp-baidu.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-mp-baidu.spec.js @@ -93,7 +93,7 @@ describe('mp:compiler-mp-baidu', () => { assertCodegen( '', '', - 'with(this){if($mp.component.data.scopedSlotsCompiler==="augmented"){const $root=$mp.data.$root;$setScopedSlotsParams("default",{"item":item})}}', + 'with(this){if($scope.data.scopedSlotsCompiler==="augmented"){const $root=$mp.data.$root;$setScopedSlotsParams("default",{"item":item})}}', { scopedSlotsCompiler: 'auto' } @@ -101,7 +101,7 @@ describe('mp:compiler-mp-baidu', () => { assertCodegen( '', '', - 'with(this){if($mp.component.data.scopedSlotsCompiler==="augmented"){const $root=$mp.data.$root;$setScopedSlotsParams("default",object)}}', + 'with(this){if($scope.data.scopedSlotsCompiler==="augmented"){const $root=$mp.data.$root;$setScopedSlotsParams("default",object)}}', { scopedSlotsCompiler: 'auto' } diff --git a/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js b/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js index c8e413fae..f6ee2963b 100644 --- a/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js @@ -110,7 +110,7 @@ describe('mp:compiler-mp-weixin', () => { assertCodegen( '', '', - 'with(this){if($mp.component.data.scopedSlotsCompiler==="augmented"){const $root=$mp.data.$root;$setScopedSlotsParams("default",{"item":item})}}', + 'with(this){if($scope.data.scopedSlotsCompiler==="augmented"){const $root=$mp.data.$root;$setScopedSlotsParams("default",{"item":item})}}', { scopedSlotsCompiler: 'auto' } @@ -118,7 +118,7 @@ describe('mp:compiler-mp-weixin', () => { assertCodegen( '', '', - 'with(this){var m0=getValue(item);$mp.data=Object.assign({},{$root:{m0:m0}});if($mp.component.data.scopedSlotsCompiler==="augmented"){const $root=$mp.data.$root;$setScopedSlotsParams("default",{"item":$root.m0})}}', + 'with(this){var m0=getValue(item);$mp.data=Object.assign({},{$root:{m0:m0}});if($scope.data.scopedSlotsCompiler==="augmented"){const $root=$mp.data.$root;$setScopedSlotsParams("default",{"item":$root.m0})}}', { scopedSlotsCompiler: 'auto' } @@ -126,7 +126,7 @@ describe('mp:compiler-mp-weixin', () => { assertCodegen( '', '', - 'with(this){if($mp.component.data.scopedSlotsCompiler==="augmented"){const $root=$mp.data.$root;$setScopedSlotsParams("default",object)}}', + 'with(this){if($scope.data.scopedSlotsCompiler==="augmented"){const $root=$mp.data.$root;$setScopedSlotsParams("default",object)}}', { scopedSlotsCompiler: 'auto' } diff --git a/packages/uni-template-compiler/lib/script/traverse/index.js b/packages/uni-template-compiler/lib/script/traverse/index.js index 506c880b5..6cd2f5b0f 100644 --- a/packages/uni-template-compiler/lib/script/traverse/index.js +++ b/packages/uni-template-compiler/lib/script/traverse/index.js @@ -117,7 +117,7 @@ module.exports = function traverse (ast, state) { if (state.options.scopedSlotsCompiler === 'auto') { const node = t.ifStatement( t.binaryExpression('===', - t.memberExpression(t.memberExpression(t.memberExpression(t.identifier('$mp'), t.identifier('component')), t.identifier(state.options.platform.name === 'mp-alipay' ? 'props' : 'data')), t.identifier('scopedSlotsCompiler')), t.stringLiteral('augmented') + t.memberExpression(t.memberExpression(t.identifier('$scope'), t.identifier(state.options.platform.name === 'mp-alipay' ? 'props' : 'data')), t.identifier('scopedSlotsCompiler')), t.stringLiteral('augmented') ), t.blockStatement([ t.variableDeclaration('const', [t.variableDeclarator(t.identifier('$root'), -- GitLab