-
-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from AdrianGonz97/chore/simplify-config
- Loading branch information
Showing
8 changed files
with
679 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"shadcn-svelte": patch | ||
--- | ||
|
||
Preserve the content of `svelte.config.js` when running the `init` command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { defaultTraveler } from './defaultTraveler' | ||
|
||
function attachCommentsToNode( | ||
traveler, | ||
state, | ||
parent, | ||
children, | ||
findHeadingComments, | ||
) { | ||
let { index } = state | ||
const { comments } = state | ||
let comment = comments[index] | ||
// Hack to tackle https://github.com/babel/minify/issues/866 | ||
let boundComments, trailingComments | ||
if (comment == null) { | ||
return | ||
} | ||
if (children == null || children.length === 0) { | ||
// No children, attach comments to parent | ||
boundComments = parent.comments != null ? parent.comments : [] | ||
while (comment != null && comment.end <= parent.end) { | ||
boundComments.push(comment) | ||
comment = comments[++index] | ||
} | ||
state.index = index | ||
if (boundComments.length !== 0 && parent.comments == null) { | ||
parent.comments = boundComments | ||
} | ||
return | ||
} | ||
// Look for heading block comments not immediately followed by a child | ||
if (findHeadingComments) { | ||
boundComments = parent.comments != null ? parent.comments : [] | ||
const { start } = children[0] | ||
while ( | ||
comment != null && | ||
(comment.type[0] === 'B' || comment.type[0] === 'M') && | ||
comment.end <= start | ||
) { | ||
boundComments.push(comment) | ||
comment = comments[++index] | ||
} | ||
if (boundComments.length !== 0 && parent.comments == null) | ||
parent.comments = boundComments | ||
} | ||
// Attach comments to children | ||
for (let i = 0, { length } = children; comment != null && i < length; i++) { | ||
const child = children[i] | ||
boundComments = [] | ||
while (comment != null && comment.end <= child.start) { | ||
boundComments.push(comment) | ||
comment = comments[++index] | ||
} | ||
// Check if next comment is line comment and on the same line if location is provided | ||
if ( | ||
comment != null && | ||
comment.loc != null && | ||
(comment.type[0] === 'L' || comment.type[0] === 'S') | ||
) { | ||
if (comment.loc.start.line === child.loc.end.line) { | ||
boundComments.push(comment) | ||
comment = comments[++index] | ||
} | ||
} | ||
if (boundComments.length !== 0) { | ||
child.comments = boundComments | ||
} | ||
// Travel through child | ||
state.index = index | ||
traveler[child.type](child, state) | ||
index = state.index | ||
comment = comments[index] | ||
} | ||
// Look for remaining comments | ||
trailingComments = [] | ||
while (comment != null && comment.end <= parent.end) { | ||
trailingComments.push(comment) | ||
comment = comments[++index] | ||
} | ||
if (trailingComments.length !== 0) { | ||
parent.trailingComments = trailingComments | ||
} | ||
state.index = index | ||
} | ||
|
||
function Block(node, state) { | ||
attachCommentsToNode(this, state, node, node.body, true) | ||
} | ||
|
||
let traveler = defaultTraveler.makeChild({ | ||
Program: Block, | ||
BlockStatement: Block, | ||
ClassBody: Block, | ||
ObjectExpression(node, state) { | ||
attachCommentsToNode(this, state, node, node.properties, true) | ||
}, | ||
ArrayExpression(node, state) { | ||
attachCommentsToNode(this, state, node, node.elements, true) | ||
}, | ||
SwitchStatement(node, state) { | ||
attachCommentsToNode(this, state, node, node.cases, false) | ||
}, | ||
SwitchCase(node, state) { | ||
attachCommentsToNode(this, state, node, node.consequent, false) | ||
}, | ||
// TODO: Consider ArrayExpression ? | ||
}) | ||
|
||
export function attachComments(node, comments) { | ||
/* | ||
Modifies in-place the AST starting at `node` by attaching the provided `comments` and returns that AST. | ||
*/ | ||
traveler[node.type](node, { | ||
comments, | ||
index: 0, | ||
}) | ||
return node | ||
} |
Oops, something went wrong.
03dd876
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
shadcn-svelte – ./
shadcn-svelte-git-main-huntabyte.vercel.app
shadcn-svelte.vercel.app
shadcn-svelte-huntabyte.vercel.app
shadcn-svelte.com
www.shadcn-svelte.com