From 0b16b2ddd0e3f0bf9ac74d7c801c9f09dbd40a1a Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Mon, 14 Jun 2021 12:00:51 -0400 Subject: [PATCH] Make doctype be case insensitive (#419) * Make doctype be case insensitive Fixes #413 * Make doctype completely case insensitive * Make check for style scoping doctype override be case insensitive * Check for doctype in the right place --- packages/astro/src/compiler/transform/doctype.ts | 2 +- .../compiler/transform/postcss-scoped-styles/index.ts | 3 +-- packages/astro/src/compiler/transform/styles.ts | 7 ++++--- packages/astro/src/internal/h.ts | 4 ++-- packages/astro/test/astro-doctype.test.js | 9 +++++++++ .../test/fixtures/astro-doctype/src/pages/capital.astro | 9 +++++++++ 6 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 packages/astro/test/fixtures/astro-doctype/src/pages/capital.astro diff --git a/packages/astro/src/compiler/transform/doctype.ts b/packages/astro/src/compiler/transform/doctype.ts index 1a0ff39e1..7647c205e 100644 --- a/packages/astro/src/compiler/transform/doctype.ts +++ b/packages/astro/src/compiler/transform/doctype.ts @@ -9,7 +9,7 @@ export default function (_opts: { filename: string; fileID: string }): Transform html: { Element: { enter(node, parent, _key, index) { - if (node.name === '!doctype') { + if (node.name.toLowerCase() === '!doctype') { hasDoctype = true; } if (node.name === 'html' && !hasDoctype) { diff --git a/packages/astro/src/compiler/transform/postcss-scoped-styles/index.ts b/packages/astro/src/compiler/transform/postcss-scoped-styles/index.ts index 63ac9fd8d..7db630764 100644 --- a/packages/astro/src/compiler/transform/postcss-scoped-styles/index.ts +++ b/packages/astro/src/compiler/transform/postcss-scoped-styles/index.ts @@ -28,8 +28,7 @@ export const NEVER_SCOPED_TAGS = new Set([ 'noscript', 'script', 'style', - 'title', - '!doctype', + 'title' ]); /** * Scope Rules diff --git a/packages/astro/src/compiler/transform/styles.ts b/packages/astro/src/compiler/transform/styles.ts index 1e459bb7f..e1199e9a6 100644 --- a/packages/astro/src/compiler/transform/styles.ts +++ b/packages/astro/src/compiler/transform/styles.ts @@ -4,13 +4,12 @@ import type { TemplateNode } from '@astrojs/parser'; import crypto from 'crypto'; import { createRequire } from 'module'; import path from 'path'; -import { fileURLToPath } from 'url'; import autoprefixer from 'autoprefixer'; import postcss, { Plugin } from 'postcss'; import postcssKeyframes from 'postcss-icss-keyframes'; import findUp from 'find-up'; import sass from 'sass'; -import { debug, error, LogOptions } from '../../logger.js'; +import { error, LogOptions } from '../../logger.js'; import astroScopedStyles, { NEVER_SCOPED_TAGS } from './postcss-scoped-styles/index.js'; import slash from 'slash'; @@ -222,7 +221,9 @@ export default function transformStyles({ compileOptions, filename, fileID }: Tr } // 2. add scoped HTML classes - if (NEVER_SCOPED_TAGS.has(node.name)) return; // only continue if this is NOT a