From 38acabfa6089ab8ac469c12b5f55022fb96935e5 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 23 Aug 2021 16:46:06 -0300 Subject: added web vendors --- .../packages/babel/src/utils/getLinariaComment.ts | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 @linaria/packages/babel/src/utils/getLinariaComment.ts (limited to '@linaria/packages/babel/src/utils/getLinariaComment.ts') diff --git a/@linaria/packages/babel/src/utils/getLinariaComment.ts b/@linaria/packages/babel/src/utils/getLinariaComment.ts new file mode 100644 index 0000000..06b3edb --- /dev/null +++ b/@linaria/packages/babel/src/utils/getLinariaComment.ts @@ -0,0 +1,31 @@ +import type { Node } from '@babel/types'; + +const pattern = /^linaria (css|styled) (.+)$/; + +export default function getLinariaComment( + path: { node: Node }, + remove: boolean = true +): ['css' | 'styled' | null, ...(string | null)[]] { + const comments = path.node.leadingComments; + if (!comments) { + return [null, null, null, null]; + } + + const idx = comments.findIndex((comment) => pattern.test(comment.value)); + if (idx === -1) { + return [null, null, null, null]; + } + + const matched = comments[idx].value.match(pattern); + if (!matched) { + return [null, null, null, null]; + } + + if (remove) { + path.node.leadingComments = comments.filter((_, i) => i !== idx); + } + + const type = matched[1] === 'css' ? 'css' : 'styled'; + + return [type, ...matched[2].split(' ').map((i) => (i ? i : null))]; +} -- cgit v1.2.3