Skip to content

Snippet migrator improperly handles multiple snippets in the same file #2836

@pokey

Description

@pokey

Input:

{
  "mobxConstructor": {
    "definitions": [
      {
        "scope": {
          "langIds": [
            "typescript",
            "javascript",
            "typescriptreact",
            "javascriptreact"
          ]
        },
        "body": [
          "constructor($parameters) {",
          "\tmakeAutoObservable(this);",
          "}"
        ]
      }
    ],
    "description": "Constructor using makeAutoObservable",
    "insertionScopeTypes": [
      "namedFunction"
    ]
  },
  "constantDeclaration": {
    "definitions": [
      {
        "scope": {
          "langIds": [
            "typescript",
            "javascript",
            "typescriptreact",
            "javascriptreact"
          ]
        },
        "body": [
          "const $name = ${value/^([^;]*);?$/$1/};"
        ],
        "variables": {
          "name": {
            "formatter": "camelCase"
          }
        }
      }
    ],
    "description": "Constant variable declaration",
    "insertionScopeTypes": [
      "statement"
    ],
    "variables": {
      "value": {
        "wrapperScopeType": "statement"
      }
    }
  },
  "constantDeclarationWithType": {
    "definitions": [
      {
        "scope": {
          "langIds": [
            "typescript",
            "javascript",
            "typescriptreact",
            "javascriptreact"
          ]
        },
        "body": [
          "const $name: $type = ${value/^([^;]*);?$/$1/};"
        ],
        "variables": {
          "name": {
            "formatter": "camelCase"
          }
        }
      }
    ],
    "description": "Constant variable declaration with type",
    "insertionScopeTypes": [
      "statement"
    ],
    "variables": {
      "value": {
        "wrapperScopeType": "statement"
      }
    }
  },
  "letDeclaration": {
    "definitions": [
      {
        "scope": {
          "langIds": [
            "typescript",
            "javascript",
            "typescriptreact",
            "javascriptreact"
          ]
        },
        "body": [
          "let $name = ${value/^([^;]*);?$/$1/};"
        ],
        "variables": {
          "name": {
            "formatter": "camelCase"
          }
        }
      }
    ],
    "description": "Let variable declaration",
    "insertionScopeTypes": [
      "statement"
    ],
    "variables": {
      "value": {
        "wrapperScopeType": "statement"
      }
    }
  },
  "letDeclarationWithType": {
    "definitions": [
      {
        "scope": {
          "langIds": [
            "typescript",
            "javascript",
            "typescriptreact",
            "javascriptreact"
          ]
        },
        "body": [
          "let $name: $type = ${value/^([^;]*);?$/$1/};"
        ],
        "variables": {
          "name": {
            "formatter": "camelCase"
          }
        }
      }
    ],
    "description": "Let variable declaration with type",
    "insertionScopeTypes": [
      "statement"
    ],
    "variables": {
      "value": {
        "wrapperScopeType": "statement"
      }
    }
  }
}

Output:

name: letDeclarationWithType
description: Let variable declaration with type
phrase: let type
insertionScope: statement

$value.wrapperPhrase: let type
$value.wrapperScope: statement
---

language: typescript | javascript | typescriptreact | javascriptreact
-
constructor($parameters) {
    makeAutoObservable(this);
}
---

language: typescript | javascript | typescriptreact | javascriptreact

$name.insertionFormatter: PRIVATE_CAMEL_CASE
-
const $name = ${value/^([^;]*);?$/$1/};
---

language: typescript | javascript | typescriptreact | javascriptreact

$name.insertionFormatter: PRIVATE_CAMEL_CASE
-
const $name: $type = ${value/^([^;]*);?$/$1/};
---

language: typescript | javascript | typescriptreact | javascriptreact

$name.insertionFormatter: PRIVATE_CAMEL_CASE
-
let $name = ${value/^([^;]*);?$/$1/};
---

language: typescript | javascript | typescriptreact | javascriptreact

$name.insertionFormatter: PRIVATE_CAMEL_CASE
-
let $name: $type = ${value/^([^;]*);?$/$1/};
---

Note how for all fields other than language (eg name, description, etc) it just takes the value from the final snippet and puts them at the top of the file.

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions