ipatalas / vscode-postfix-ts

Postfix notation for TypeScript/Javascript - extension for VS Code
MIT License
158 stars 43 forks source link

does not work with strings, strange behaviour when ${} variables present in string literals #48

Closed numeralz closed 2 years ago

numeralz commented 3 years ago
  "postfix.customTemplates": [
    {
      "body": "try{\n  const {\n    data,\n  } = await axios.request( {\n    method : \"${1:get}\",\n    url    : {{expr}},\n  } );\n  // handle result\n  $2\n}\ncatch( error ){\n  console.error( error );\n}",
      "description": "AxiosReq",
      "name": "axiosget",
      "when": []
    }
  ]
const userId=1;
const postId=1;
`/api/user/${userId}/posts/${postId}`.axiosget

expansion produces:

`/api/user/${userId}/posts/${try{
  const {
    data,
  } = await axios.request( {
    method : "get",
    url    : postId}`,
  } );
  // handle result

}
catch( error ){
  console.error( error );
}

expected:


try{
  const {
    data,
  } = await axios.request( {
    method : "get",
    url    : `/api/user/${userId}/posts/${postId}`,
  } );
  // handle result

}
catch( error ){
  console.error( error );
}

actually, further investigation shows that it does not really work for strings.

ipatalas commented 3 years ago

Hi, thanks for reporting. It really doesn't work for strings. That's amazing I haven't noticed that before :D I'll have a look into that.

Capyhw commented 2 years ago

does this resolved?

ipatalas commented 2 years ago

Hi, sorry it took so long but got it figured out: image

There is one more thing I'd like to do before next release but I hope it will happen in the upcoming days.

ipatalas commented 2 years ago

Fixed in 1.10.0