Skip to main content
Create new
Introduction
Reactivity
Props
Logic
Events
Bindings
Lifecycle
Stores
Motion
Transitions
Animations
Easing
SVG
Actions
Classes
Component composition
Context API
Special elements
Module context
Debugging
7GUIs
Miscellaneous
App.svelte
Tag-input.svelte
<script>
import TagInput from "./Tag-input.svelte";

let tags = [];
let suggestions = ["Paris", "New York", "Yaounde"]
</script>

<i>Comma or Enter to separate tags : </i>

<TagInput list={suggestions} bind:value={tags}/>

<ul>
{#each tags as t}
<li>{t}</li>
{/each}
</ul>
fetching https://unpkg.com/clsx@2.1.1/dist/clsx.mjs
import 'svelte/internal/disclose-version';
import 'svelte/internal/flags/legacy';
import * as $ from 'svelte/internal/client';
import TagInput from "./Tag-input.svelte";

var root_1 = $.template(`<li> </li>`);
var root = $.template(`<i>Comma or Enter to separate tags :</i> <!> <ul></ul>`, 1);

export default function App($$anchor) {
let tags = $.mutable_state([]);
let suggestions = ["Paris", "New York", "Yaounde"];
var fragment = root();
var node = $.sibling($.first_child(fragment), 2);

TagInput(node, {
list: suggestions,
get value() {
return $.get(tags);
},
set value($$value) {
$.set(tags, $$value);
},
$$legacy: true
});

var ul = $.sibling(node, 2);

$.each(ul, 5, () => $.get(tags), $.index, ($$anchor, t) => {
var li = root_1();
var text = $.child(li, true);

$.reset(li);
$.template_effect(() => $.set_text(text, $.get(t)));
$.append($$anchor, li);
});

result = svelte.compile(source, {
generate: ,
});
/* Add a <style> tag to see the CSS output */
		
			
				
  • Root {
    • css: null
    • js: []
    • start: 133
    • end: 278
    • type: "Root"
    • fragment: Fragment {...}
      • type: "Fragment"
      • nodes: [...] (6)
        • Text {...}
          • type: "Text"
          • start: 131
          • end: 133
          • raw: "\n\n"
          • data: "\n\n"
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 133
          • end: 174
          • name: "i"
          • attributes: []
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (1)
              • Text {...}
                • type: "Text"
                • start: 136
                • end: 170
                • raw: "Comma or Enter to separate tags :"
                • data: "Comma or Enter to separate tags :"
                }
              ]
            }
          }
        • Text {...}
          • type: "Text"
          • start: 174
          • end: 176
          • raw: " "
          • data: " "
          }
        • Component {...}
          • type: "Component"
          • start: 176
          • end: 224
          • name: "TagInput"
          • attributes: [...] (2)
            • Attribute {...}
              • type: "Attribute"
              • start: 186
              • end: 204
              • name: "list"
              • value: ExpressionTag {...}
                • type: "ExpressionTag"
                • start: 191
                • end: 204
                • expression: Identifier {...}
                  • type: "Identifier"
                  • start: 192
                  • end: 203
                  • loc: {...}
                    • start: {...}
                      • line: 10
                      • column: 16
                      }
                    • end: {...}
                      • line: 10
                      • column: 27
                      }
                    }
                  • name: "suggestions"
                  }
                }
              }
            • BindDirective {...}
              • start: 205
              • end: 222
              • type: "BindDirective"
              • name: "value"
              • expression: Identifier {...}
                • type: "Identifier"
                • start: 217
                • end: 221
                • loc: {...}
                  • start: {...}
                    • line: 10
                    • column: 41
                    }
                  • end: {...}
                    • line: 10
                    • column: 45
                    }
                  }
                • name: "tags"
                }
              • modifiers: []
              }
            ]
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: []
            }
          }
        • Text {...}
          • type: "Text"
          • start: 224
          • end: 226
          • raw: " "
          • data: " "
          }
        • RegularElement {...}
          • type: "RegularElement"
          • start: 226
          • end: 278
          • name: "ul"
          • attributes: []
          • fragment: Fragment {...}
            • type: "Fragment"
            • nodes: [...] (3)
              • Text {...}
                • type: "Text"
                • start: 230
                • end: 232
                • raw: "\n\t"
                • data: "\n\t"
                }
              • EachBlock {...}
                • type: "EachBlock"
                • start: 232
                • end: 272
                • expression: Identifier {...}
                  • type: "Identifier"
                  • start: 239
                  • end: 243
                  • loc: {...}
                    • start: {...}
                      • line: 13
                      • column: 8
                      }
                    • end: {...}
                      • line: 13
                      • column: 12
                      }
                    }
                  • name: "tags"
                  }
                • body: Fragment {...}
                  • type: "Fragment"
                  • nodes: [...] (3)
                    • Text {...}
                      • type: "Text"
                      • start: 249
                      • end: 251
                      • raw: "\n\t"
                      • data: "\n\t"
                      }
                    • RegularElement {...}
                      • type: "RegularElement"
                      • start: 251
                      • end: 263
                      • name: "li"
                      • attributes: []
                      • fragment: Fragment {...}
                        • type: "Fragment"
                        • nodes: [...] (1)
                          • ExpressionTag {...}
                            • type: "ExpressionTag"
                            • start: 255
                            • end: 258
                            • expression: Identifier {...}
                              • type: "Identifier"
                              • start: 256
                              • end: 257
                              • loc: {...}
                                • start: {...}
                                  • line: 14
                                  • column: 6
                                  }
                                • end: {...}
                                  • line: 14
                                  • column: 7
                                  }
                                }
                              • name: "t"
                              }
                            }
                          ]
                        }
                      }
                    • Text {...}
                      • type: "Text"
                      • start: 263
                      • end: 265
                      • raw: "\n\t"
                      • data: "\n\t"
                      }
                    ]
                  }
                • context: Identifier {...}
                  • type: "Identifier"
                  • name: "t"
                  • start: 247
                  • loc: {...}
                    • start: {...}
                      • line: 13
                      • column: 16
                      • character: 247
                      }
                    • end: {...}
                      • line: 13
                      • column: 17
                      • character: 248
                      }
                    }
                  • end: 248
                  • typeAnnotation: undefined
                  }
                • index: undefined
                • key: undefined
                }
              • Text {...}
                • type: "Text"
                • start: 272
                • end: 273
                • raw: "\n"
                • data: "\n"
                }
              ]
            }
          }
        ]
      }
    • options: null
    • instance: Script {...}
      • type: "Script"
      • start: 0
      • end: 131
      • context: "default"
      • content: Program {...}
        • type: "Program"
        • start: 8
        • end: 122
        • loc: {...}
          • start: {...}
            • line: 1
            • column: 0
            }
          • end: {...}
            • line: 6
            • column: 0
            }
          }
        • body: [...] (3)
          • ImportDeclaration {...}
            • type: "ImportDeclaration"
            • start: 10
            • end: 52
            • loc: {...}
              • start: {...}
                • line: 2
                • column: 1
                }
              • end: {...}
                • line: 2
                • column: 43
                }
              }
            • specifiers: [...] (1)
              • ImportDefaultSpecifier {...}
                • type: "ImportDefaultSpecifier"
                • start: 17
                • end: 25
                • loc: {...}
                  • start: {...}
                    • line: 2
                    • column: 8
                    }
                  • end: {...}
                    • line: 2
                    • column: 16
                    }
                  }
                • local: Identifier {...}
                  • type: "Identifier"
                  • start: 17
                  • end: 25
                  • loc: {...}
                    • start: {...}
                      • line: 2
                      • column: 8
                      }
                    • end: {...}
                      • line: 2
                      • column: 16
                      }
                    }
                  • name: "TagInput"
                  }
                }
              ]
            • source: Literal {...}
              • type: "Literal"
              • start: 31
              • end: 51
              • loc: {...}
                • start: {...}
                  • line: 2
                  • column: 22
                  }
                • end: {...}
                  • line: 2
                  • column: 42
                  }
                }
              • value: "./Tag-input.svelte"
              • raw: "\"./Tag-input.svelte\""
              }
            }
          • VariableDeclaration {...}
            • type: "VariableDeclaration"
            • start: 55
            • end: 69
            • loc: {...}
              • start: {...}
                • line: 4
                • column: 1
                }
              • end: {...}
                • line: 4
                • column: 15
                }
              }
            • declarations: [...] (1)
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 59
                • end: 68
                • loc: {...}
                  • start: {...}
                    • line: 4
                    • column: 5
                    }
                  • end: {...}
                    • line: 4
                    • column: 14
                    }
                  }
                • id: Identifier {...}
                  • type: "Identifier"
                  • start: 59
                  • end: 63
                  • loc: {...}
                    • start: {...}
                      • line: 4
                      • column: 5
                      }
                    • end: {...}
                      • line: 4
                      • column: 9
                      }
                    }
                  • name: "tags"
                  }
                • init: ArrayExpression {...}
                  • type: "ArrayExpression"
                  • start: 66
                  • end: 68
                  • loc: {...}
                    • start: {...}
                      • line: 4
                      • column: 12
                      }
                    • end: {...}
                      • line: 4
                      • column: 14
                      }
                    }
                  • elements: []
                  }
                }
              ]
            • kind: "let"
            }
          • VariableDeclaration {...}
            • type: "VariableDeclaration"
            • start: 71
            • end: 121
            • loc: {...}
              • start: {...}
                • line: 5
                • column: 1
                }
              • end: {...}
                • line: 5
                • column: 51
                }
              }
            • declarations: [...] (1)
              • VariableDeclarator {...}
                • type: "VariableDeclarator"
                • start: 75
                • end: 121
                • loc: {...}
                  • start: {...}
                    • line: 5
                    • column: 5
                    }
                  • end: {...}
                    • line: 5
                    • column: 51
                    }
                  }
                • id: Identifier {...}
                  • type: "Identifier"
                  • start: 75
                  • end: 86
                  • loc: {...}
                    • start: {...}
                      • line: 5
                      • column: 5
                      }
                    • end: {...}
                      • line: 5
                      • column: 16
                      }
                    }
                  • name: "suggestions"
                  }
                • init: ArrayExpression {...}
                  • type: "ArrayExpression"
                  • start: 89
                  • end: 121
                  • loc: {...}
                    • start: {...}
                      • line: 5
                      • column: 19
                      }
                    • end: {...}
                      • line: 5
                      • column: 51
                      }
                    }
                  • elements: [...] (3)
                    • Literal {...}
                      • type: "Literal"
                      • start: 90
                      • end: 97
                      • loc: {...}
                        • start: {...}
                          • line: 5
                          • column: 20
                          }
                        • end: {...}
                          • line: 5
                          • column: 27
                          }
                        }
                      • value: "Paris"
                      • raw: "\"Paris\""
                      }
                    • Literal {...}
                      • type: "Literal"
                      • start: 99
                      • end: 109
                      • loc: {...}
                        • start: {...}
                          • line: 5
                          • column: 29
                          }
                        • end: {...}
                          • line: 5
                          • column: 39
                          }
                        }
                      • value: "New York"
                      • raw: "\"New York\""
                      }
                    • Literal {...}
                      • type: "Literal"
                      • start: 111
                      • end: 120
                      • loc: {...}
                        • start: {...}
                          • line: 5
                          • column: 41
                          }
                        • end: {...}
                          • line: 5
                          • column: 50
                          }
                        }
                      • value: "Yaounde"
                      • raw: "\"Yaounde\""
                      }
                    ]
                  }
                }
              ]
            • kind: "let"
            }
          ]
        • sourceType: "module"
        }
      • attributes: []
      }
    }
The AST is not public API and may change at any point in time
Multiple tags input • Playground • Svelte